Can anyone point me to some best practices for java coding?
Pracices following which will make codes more robust.
Printable View
Can anyone point me to some best practices for java coding?
Pracices following which will make codes more robust.
My recommendation is Suns' coding conventions in Java programming.
Code Conventions for the Java(TM) Programming Language: Contents
Along with that, I would suggest doing things in a consistent manner. Choose an approach for routine things, and always do it the same way. Basically, avoid taking coding short cuts. Consistency allows others to get a feel for your style, and it also helps you to avoid making trivial mistakes that are sometimes hard to find.
Stevie, could you please give an example of what you mean about consistency? I do not really follow.
I think he's talking about a common ways all others following. Same design pattern may be, which most people do.
Here is a good example. You can write an "if" statement two ways:
if (condition) method();
if (condition) {
method();
}
Both are correct, but the first way only works if you only want to execute one statement after the "if". The second way always works. I *always* put braces after an "if", even when it is not necessary.
This sounds trivial, but my point is that there are many little things like this. If you do these many little things each in a consistent manner, then your coding style will appear consistent to others. Not to mention, when you come back to something you wrote after two years, you will be able to figure out what you did ;-)
Another good habit is to write brief, meaningful comments *while* you code. A good comment should be a short as possible, but no shorter. Explain *why* you are doing something; the code should be clear enough to to say *what* you are doing.
If you are a professional programmer, then other people will work on the code you write. Remember to treat them the way you want to be treated.