On comments

|

Jeff Atwood: Code Tells You How, Comments Tell You Why.

Indeed, this is a fantastic comment:

/* A binary search turned out to be slower than the Boyer-Moore
algorithm for the data sets of interest, thus we have used the more
complex, but faster method even though this problem does not at
first seem amenable to a string search technique. */

However, I would suggest not to add the comment

# Reverse the string

to document the Pearl statement

$string = join('',reverse(split('',$string)));

I would prefer to wrap the code (even if it is a one-liner) into a function `reverse_string()` instead. That way, we got rid of a comment and reduced duplication in the code.

About this Entry

This page contains a single entry by HMK published on December 20, 2006 2:26 PM.

Skype / VOIP & NATs was the previous entry in this blog.

Bahn is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.