
Java Coding Standards
Aim
These standards are intended to ensure:
- Consistency across the project in coding style (bracketing, variable naming conventions, etc) which helps maintenance.
- Our code is as bug-free as possible (avoding common pitfalls, code review, test practices)
- Our code provides the extra information and services that we want (javadoc, versioning)
See also http://www.martinhill.me.uk/articles/Technical/JavaCodingStyle.shtml
Development Environment
Assume JDK 1.4, as this seems quite stable, and includes a logging API. There is a component org.astrogrid.log.Log in the common CVS directory, which can be used as a general interface to whatever logging API we end up using (eg Log4J ).
IDEs are up to you. Most people are using the Support.Eclipse IDE. Some people are using unix editors, command line compilers and Ant. Personally, I use CodeGuide, which has one-click dependency-checked compiler and a lovely built in debugger.
Coding Standards
Coding Standards are based on the Elements of Java Style book – buy it and put it on expenses. See also:
- Amby Soft Java Code Std – the basis for the recommended book
- StdCodingOptimisation
- StdCodingPitfalls / Gotchas / Hints & Tips
- StdCodeReviews
- StdCodingStyle – original project draft
Amendments
- (99) Double checked locking is not safe in java don’t use it.
Points
- Things like number of spaces per indent and tabs vs spaces can occupy hours of fun in pubs (I go to the wrong pubs) but please, if we all stick to the project standard 3 spaces/indent and spaces instead of tabs, all our ‘intelligent’ IDEs can align things correctly…
Deployment:
I (MCH) don’t know much about this, please someone who does add something useful:
- JAR files, packages, manifests, versioning
- Versioning
- Versioning: http://java.sun.com/j2se/1.4/docs/guide/versioning/spec/VersioningSpecification.html
- Tutorial: see javaworld, http://www.javaworld.com/javaworld/jw-09-2002/jw-0920-jpvs-p1.html
— TonyLinde – 24 Sep 2002, MartinHill – Sep 2003 — KeithNoddle – 04 Dec 2002
Resources
- “Official” Sun: http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html but not sure that these are really conventions yet…
- Semi-famous Draft guidelines: http://gee.cs.oswego.edu/dl/html/javaCodingStd.html
- Maintainability notes: http://www-2.cs.cmu.edu/~jch/java/maintainability.html
- Optimisation: (don’t do it) http://www-2.cs.cmu.edu/~jch/java/optimization.html
- Style: http://web.archive.org/web/20010423123907/www.numeric-quest.com/news/NQ-comments.html
- Roedy Green’s Gotchas: http://mindprod.com/jgloss/gotchas.html * Java World
(AstroGrid
Leave a comment