Types of Comments

One of the most neglected features of programming languages is the comment system. Not that there isn’t discussion of the nature of programming comments – people are endlessly pondering how many comments to use, how to write code that’s “auto-commenting”,

As I see it, there are three major categories of program comments: descriptive, to-do, and comment-out. Programming languages should support native ways to differentiate these types of comments; none that I know of does and most don’t have very many styles of comment at all.

Descriptive comments are the standard, and the ones everyone talks about. They include program “headstones” that describe what the program is supposed to do, inputs/outputs, log history of changes, etc.

/*
program: whatever

revision history:...

author:...
*/
...
//this function turns a 6-digit date string into a unix date
...
$foobar = $foo ^ 2 / $bar; //standard accounting forumula

 

To-Do comments are dropped into programs while you’re working on – a “note to self” about something that needs to be fixed, or might be a problem later. I use php-style hash comments for these, but most languages don’t support different styles of comments, so I do a standard comment followed by a hash (//#!error or REM #?values should be global, for example). I use #! for action items, things that are likely to crash if they aren’t fixed, #? for things that probably should be fixed but probably won’t cause a crash. Then before a program is released, I can look for #! that must be fixed, or #? that need attention. Finally, I also use to-do style comments for printing/hiding debug messages while I’m working on the code; before release these should be removed.

#!this will fail if we get more than 10 users
#!divide by zero error
#?will a salesman ever sell more than 10,000 items?
#?this code is ugly, could be refactored
#echo "$user : ".print_r($user, true);

 

Comment Out are comments that are applied to actual code, to disable it while leaving it in place. Sometimes this is to test different methods; sometimes it’s no longer used but you’re keeping it for reference; usually you’re trying taking it out to see what it does. In PHP I use # for these, to differentiate them from descriptive // comments.

#old version
#$foobar = $foo ^ 2 / $bar; //standard accounting forumula
#new version, double the results
$foobar = 2 * ($foo ^ 2 / $bar) ; //standard accounting forumula
...
/* Removed: we no longer need user ID
$user_id = lookup($user_value);
if ($user_id = 0) {
$user_id = request_from_server($user_value);
}
*/

 

I tend to like descriptive comments to be lined up with the code, and todo/comment-out shifted to the left so I can see them when I’m looking through the code:

                //loop through users, capitalize their names
foreach ($users as $user) {
#echo "$user : ".print_r($user, true);
$user->name = ucase($user->name);
#don't ucase user address
# $user->address = ucase($user->address);
#!user phone number needs to be parsed
}

Code editors that auto-indent code (Visual Studio) and langauges that are indent-dependent (Python) defeat this strategy.

 

Types of Comments

As I see it, there are three major categories of program comments: descriptive, to-do, and comment-out. Programming languages should support native ways to differentiate these types of comments; none that I know of does and most don't have very many styles of comment at all.

Descriptive comments are the standard, and the ones everyone talks about. They include program “headstones” that describe what the program is supposed to do, inputs/outputs, log history of changes, etc.

/*
program: whatever

revision history:...

author:...
*/
...
//this function turns a 6-digit date string into a unix date
...
$foobar = $foo ^ 2 / $bar; //standard accounting forumula

To-Do comments are dropped into programs while you're working on – a “note to self” about something that needs to be fixed, or might be a problem later. I use php-style hash comments for these, but most languages don't support different styles of comments, so I do a standard comment followed by a hash (//#!error or REM #?values should be global, for example). I use #! for action items, things that are likely to crash if they aren't fixed, #? for things that probably should be fixed but probably won't cause a crash. Then before a program is released, I can look for #! that must be fixed, or #? that need attention. Finally, I also use to-do style comments for printing/hiding debug messages while I'm working on the code; before release these should be removed.

#!this will fail if we get more than 10 users
#!divide by zero error
#?will a salesman ever sell more than 10,000 items?
#?this code is ugly, could be refactored
#echo "$user : ".print_r($user, true);

Comment Out are comments that are applied to actual code, to disable it while leaving it in place. Sometimes this is to test different methods; sometimes it's no longer used but you're keeping it for reference; usually you're trying taking it out to see what it does. In PHP I use # for these, to differentiate them from descriptive // comments.

#old version
#$foobar = $foo ^ 2 / $bar; //standard accounting forumula
#new version, double the results
$foobar = 2 * ($foo ^ 2 / $bar) ; //standard accounting forumula
...
/* Removed: we no longer need user ID
$user_id = lookup($user_value);
if ($user_id = 0) {
$user_id = request_from_server($user_value);
}
*/

I tend to like descriptive comments to be lined up with the code, and todo/comment-out shifted to the left so I can see them when I'm looking through the code:

//loop through users, capitalize their names
foreach ($users as $user) {
#echo "$user : ".print_r($user, true);
$user->name = ucase($user->name);
#don't ucase user address
# $user->address = ucase($user->address);
#!user phone number needs to be parsed
}

Code editors that auto-indent code and langauges that are indent-dependent defeat this strategy.

Buddhaphone

Yes, I’ll be getting an iPhone 2.0 (or as I’m choosing to call it, hoping it will catch on, the “Buddhaphone”) but not this weekend when it first comes out, because I have to wait for my Verizon contract to run out at the end of the month. In the meantime, I’ll probably download the new software for my iPod Touch.

The Palm Treo 650 hasn’t been bad – with Missing Sync it syncs to my Mac fairly well. Verizon’s coverage is great, I’ll miss that with AT&T. But Verizon is also about way behind the technology curve; they recently announced and available upgrade to the Palm Centro (the new, smaller version of the Treo) that’s been available on ATT for over a year now.

The Palm has convinced me of the value of a smartphone, though, and the new iPhone should go above and beyond that. On a daily basis I use mobile web to look things up on Google and Yelp, and check that websites are working; Google Maps is now indispensable, paper maps to the contrary. The address book is my main reference (especially since it’s well-sync’d with my desktop), as well as the calendar, even though I still manage to miss birthdays and other notable occasions. I keep notes – grocery and affinity card numbers, shopping lists, busy day todo lists, ideas for t-shirt slogans (“Mentally Confused and Prone to Wandering”), beers I’ve tried, medical history… I used to use Pocket Quicken a lot but when my desktop Quicken fell down and couldn’t get up it took a lot of my enthusiasm away. I rarely use the camera – and I think people who go around holding up their phones and clicking pictures seem nearly as idiotic as the ones who keep a bluetooth headset in their ear when they’re not talking on it. And of course I’ve got an HP-12C emulator – there’s a hacked one for the iPhone as well (and even an HP-16C!) – hope they’ll make it to the new iPhone, hacked or not.

I actually read a book this weekend (“Down and Out in the Magic Kingdom” by Cory Doctorow) on my iPod Touch. The battery doesn’t last all that long when you’ve got the backlight on the whole time, and you have to keep swiping the screen to scroll but all in all it wasn’t that bad an experience, and you can’t beat the portability.

Yelp

I signed up on Yelp about a year ago, looked around, didn't find a whole lot of reviews. Recently returned because the guys on the radio were talking about it – and now it seems to be approaching useful mass.

So stop reading here, there's nothing new (by a long shot!) – go to Yelp – read reviews, sign in, write some reviews. Link me as a friend, if you're so inclined – address is fheald at this website's domain name.