Personal tools
You are here: Home technical Java coding, templates and comments
Document Actions

Java coding, templates and comments

by Ramarao Kanneganti last modified 2006-08-17 08:14

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
//
Let us see what is wrong with this one. First of all, the
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
//
//
Of course these comments are utterly useless, and adds to background noise.

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?

  1. Configure the starting file to right template.
  2. Use javadoc comments
  3. 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.

Multi-threaded Java Server

Posted by Anonymous User at 2010-03-03 18:48

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


Powered by Plone, the Open Source Content Management System

This site conforms to the following standards: