CCCC Code Comment Craziness
I’ve had a lot of free time lately, and I’ve used some of it to pick up the programming language Perl. I don’t consider myself a real programmer, but I’ve done enough coding for various things to realize how useful it is.
Also, I’ve done enough coding to realize how valuable comments are. While teaching Matlab to freshmen, I was consistently frustrated on how little they commented. I usually told them that I’d take points off if they didn’t comment enough, and in my examples I tried to include lots of comments (sometimes over half of the total text of each .m file), but usually to no avail.
Occasionally they did, though, and this was helpful in ways I hadn’t expected. Once, while looking at two submissions, I was struck by how similar they were; in fact, identical! Now, it’s easy enough for two simple scripts to be the same… but the clincher was the identical comments (including a mis-spelling). Ha!
Anyway, I’m kind of crazy about comments in code. The other day, I was writing a Reverse-Polish calculator in Perl, just to try it out, you know? and this is the beginning section:
# start by defining variables:
my $number1; # is... you know who!
my $number2; # not a polite topic for conversation
my $operation; # I knocked was out for most of it, but the doctor saved the part in a jar, wanna see it?
my $wholeBigString; # where I store the entire thing put together, i.e. "5+3" or something
my $choice; # isn't it always?
my $answer; # is mine; yours may be different.
The rest is actually more boring, and in addition it doesn’t work quite right, proving my earlier assertion that I’m not an actual programmer. But, I’ll figure it out soon.
Have a nice day.