X-Received: by 10.224.189.78 with SMTP id dd14mr1257649qab.0.1359494057371; Tue, 29 Jan 2013 13:14:17 -0800 (PST) X-Received: by 10.182.5.231 with SMTP id v7mr15067obv.9.1359494057304; Tue, 29 Jan 2013 13:14:17 -0800 (PST) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!p13no7880802qai.0!news-out.google.com!k2ni3907qap.0!nntp.google.com!p13no6126691qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Tue, 29 Jan 2013 13:14:16 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T NNTP-Posting-Host: 69.28.149.29 References: <3d960018-349d-456b-a533-c0d05d2c9aaf@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <650990c3-38b0-4fef-9ccf-6ad907b52039@googlegroups.com> Subject: Re: Reading Code Standard From: Lew Injection-Date: Tue, 29 Jan 2013 21:14:17 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.java.programmer:21842 Martin Gregorie wrote: > subhabangalore wrote: >> The suggestions and the solutions given by the learned members of the >> group are very nice. Thank you for your kind time. > >> Now as a new learner of the language, I am trying to consolidate my >> learning. > >> I want to read about good coding standards, and read some good codes in >> its various aspects. > > I think "The Practice of Programming" by Brian Kernighan and Rob Pike is > well worth having. It describes good approached to naming, program layout > and writing programs so they are easier to debug and maintain. There's > not a lot about Java in it (its main focus is on C) but what it says is > generally applicable to block structured languages: it gives examples in > C, C++, Java, and Perl but its suggestions would be equally applicable to > Python and Pascal. As mentioned upthread, there are standards specific to Java. They boil down to: - Use camel case for identifiers except constant variables. - Start variable and method names (except constant variables) with a lower-case letter. - Start type names with an upper-case letter. - Constant variables are spelled with all upper case, with word parts separated by underscores. - Do not use underscores for any other identifiers, and do not use the dollar sign "$" in identifiers. - Indent four spaces (or two) per indent level. DO NOT USE TAB CHARACTERS TO INDENT. - Enclose all sub-statements (conditional blocks, loop blocks, initializers, ...) in braces. - Use either K&R brace placement or put the opening brace on its own line aligned with the control line. (The second approach is unofficial but widely used.) - Declare static variables (constants first), then static methods, then instance variables, then instance methods within a type. (Reasonable deviations exist.) - Use fully descriptive variable names. (Avoid shorthand like 'int s = ...'.) - Javadoc all elements accessible outside the type. - Names should reflect algorithmic purpose, not data type. There's more, but that'll get you started. -- Lew