Ricebridge
Search This Site
Jul 29 2010 17:04 UTC

Got a question for us?
Just Ask!


$15 Gift Certificate for every bug you find.

  • Visa MasterCard
  • Visa Delta Laser
  • WorldPay

Bookmark Source code standards for Ricebridge Java Components at del.icio.us Digg Source code standards for Ricebridge Java Components at Digg.com Bookmark Source code standards for Ricebridge Java Components at reddit.com Bookmark Source code standards for Ricebridge Java Components at YahooMyWeb Bookmark Source code standards for Ricebridge Java Components at Spurl.net Bookmark Source code standards for Ricebridge Java Components at Simpy.com Bookmark Polyphasic Mutants at NewsVine Blink this Source code standards for Ricebridge Java Components at blinklist.com Bookmark Source code standards for Ricebridge Java Components at Furl.net Fark Source code standards for Ricebridge Java Components at Fark.com

Ricebridge Coding Standards

Coding standards are an essential part of developing high quality software. They create a consistent and reliable base for testing, evolving and evaluating all the code that goes into our components. We haven't just thrown together a few methods and classes that seem to work. We pay attention to the details, so that everything comes together to make our components rock solid.

We are making our coding standards publicly available because we want to demonstrate that we take the quality of our work seriously. We stand by what we do and we want you to know that when you use our components, you can be sure that we have nit-picked every detail.

By the way, we do not use Hungarian Notation, which we think is a bit silly and over-the-top. Rather, we use a practical set of prefixes, that show meaning, not type (that's what compilers are for!). This means that you can tell instantly, just by looking, what will happen when you use a variable.

Our conventions are designed as additions and modifications to the standard Java conventions, which we use as the default standard.

Coding Standards

1. Choice of Name
We try to choose names that mean something, even out of context. We usually avoid abbreviations that drop vowels, preferring to use root syllables. In general, names should be fairly short, but with modern auto-completion longer names are also usable.


2. Instance Variables

private String iFoo = "bar";
We use the prefix i to indicate an instance variable.



3. Static Variables

private static String[] sFoo = new String[] {"bar"};
We use the prefix s to indicate a static variable.



4. Parameters

public void method( String pParam ) {}
This one helps you spot those nasty argument modification bugs (Did I say argument, shucks I meant parameter, no wait, argument, erm... let's just use p to save confusion).



4. Local Variables

int foo = 101;
Start in lowercase, and avoid underscores if possible. StudlyCaps are not always required if the name is relatively short.



5. Iteration Variables

for( int rowI = 0; rowI < rows.length; rowI++ )
Yeah, it's a suffix. The idea is that the traditional i,j,k are best left for mathematics papers, which are meant to be impenetrable. When you code, you code to be understood. So even simple iteration variables should tell you what they are iterating. This convention also applies to Iterators.



6. Always Use Brackets

if( true ) { doThis(); } 
Sorry, but there will come a time when a single line needs to be expanded, and then you will forget to put in the brackets and waste half a day bug-hunting. No thanks. Anyway, if you always put in the brackets, everybody else knows what you meant. (If you want to call them parentheses, you can, but bracket is easier to spell).



7. Indent! Indent! Indent!
"Indent according to program flow", Tom said logically. Frankly, incorrect and inconsistent indentation is just not going to cut it. We like to use two spaces, as that gives you more horizontal space. If it's a new code block it gets a new indent, period. And please don't use tabs!


8. Bracket Wars
Well, this one is sure to please. The number one cause of permanent injury among programmers. We've chosen a compromise between the space-wasting bracket-gets-its-own-line-and-indent and the confusing "squash-em-and-see" approach. Basically, if, else, for, while, try, catch and friends should all start on a new line and never have a preceding bracket, like so

if( true ) {
  doThis();
}
else {
  doThat();
}

We think this style highlights the logic of the code and keeps things nicely aligned.


9. Alignment
This is one we picked up from Code Complete and also from The Non-Designer's Design Book. The basic idea is that stuff that goes together should be closer together physically than stuff that isn't, semantically speaking. For example:

private String iFirst  = "bar";
private int    iSecond = 202;


10. Separation
This is the same idea as the last convention, but applied to whitespace between methods and code blocks within methods. Don't jam everything together, space it out and put methods that are related closer to each other than methods that aren't. We tend to separate methods with two lines, and groups of methods with three lines. Inside methods, we tend to use one line to separate logical blocks.


11. Comments
Javadoc comments are absolutely required. Well, we are writing components, and we do sell the source code, so this is part of the product. We tend towards the idea that code should be self-documenting, but an occasional inline comment or two is not going to hurt anybody.


12. Use Common Sense
"First, your return to shore was not part of our negotiations nor our agreement, so I must do nothin'. And secondly, you must be a pirate for the Pirate's Code to apply, and you're not. And thirdly, the Code is more what you'd call "guidelines" than actual rules. Welcome aboard the Black Pearl, Miss Turner."
   Captain Barbossa (Geoffrey Rush), Pirates of the Caribbean


So there you go, that's how we do things. If you have any views on our coding conventions, particularly strongly-held dogmatic ones, we'd love to hear them!

comment on this page Home | Search | About Us | Contact Us | Our Products | Documentation | Resources | Login
Copyright © 2004-2010 Ricebridge. All Rights Reserved.