No more comments in your code

Comments, the more the better… right? Well I thought so too, in fact this is some of my code of a few days ago:

// handle the initialization of jobs
if (request.getParameter("initiateJobs") != null && request.getParameter("initiateJobs").equalsIgnoreCase("true")) {
	initializeJobs();
}

// get the trigger info, which will be displayed on the jsp page
List triggerInfo = getTriggerInfo();
request.setAttribute("triggerInfo", triggerInfo);

But what does it really add? Besides two lines of text. The code in the ‘if’ statement should be clear enough for a web programmer, and the method ‘initializeJobs’ tells as much as the comment. Same goes for the two lines of code below that. What would my intention be by putting ‘triggerInfo’ on the request scope? Point made.

Maybe you say ‘it’s faster to read’. Well… I don’t think it is.

if (request.getParameter("initiateJobs") != null && request.getParameter("initiateJobs").equalsIgnoreCase("true")) {
	initializeJobs();
}

List triggerInfo = getTriggerInfo();
request.setAttribute("triggerInfo", triggerInfo);

Looking at one of my last lines of code I realized Sammy Larbi and Jeff Atwood have a point.

This entry was posted in General and tagged , . Bookmark the permalink.

2 Responses to No more comments in your code

  1. tetsuoii says:

    If your code is as useless and redundant as your comments it must be a nightmare to read.

  2. Mark says:

    The usefullness of the code is hard to see without the context of the application, if you think it’s a nightmare to read then I’m glad you’re maintaining someone else’s code :-)

    What this post tried to get across is that (some) comments are redundant. Too bad you missed the point of the post.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>