Java coding, templates and comments
Written in 2003. While doing some code reviews, I wrote the following blog. Moved it out to the internet now.
I have been reading a bit of code lately and editing it to cofirm to good coding standards. I want to share it with all of you.
First off all, do not write code without good starting template or an editor. I have come to realize that eclipse is as good as en editor emacs is, especially given the plethora of plugins.
In any case, here is what I saw:
// // Filename: xxxxx // author: xxxxx // date: xxxx // History: xxxxx // some description //
filename may change. People may not maintain dates. The authors may keep on getting added. Only thing meaningful here is description, but that belongs in javadoc anyway.
So, here is my prescription to start the file:
//$Id$
That is all! The version control mechanism will fill in all the details.
Next, I saw comments like the following:
class Foo {
//------------ private variables
int fooInt;
String fooString;
//
// CONSTRUCTORS
//
//
Remember this: Whenever you repeat what is in the code in comments, you are insulting the reader.
Other errors I saw are:
import java.util.*
import javax.*
Why import unnecessary modules? Specify only the ones you need. That helps the readers much better. Also, the dependencies can easily be understood.
I find that by using a modern IDE like eclipse, several of these problems can be avoided. How?
- Configure the starting file to right template.
- Use javadoc comments
- Do not import any modules. Let the IDE organize the modules for you. It does pretty good job. In fact, better job than you.
I will write more on the IDEs and java coding standards in forth coming articles.
Here we will try to explain the basic mechanisms of communication via sockets by building a java multiclient server. Read more from the whole guide of "Multi-threaded Java Server" at: http://forums.techarena.in/guides-tutorials/1311302.htm