Comment of the Day: Gulp

October 12th, 2009

PageControl pc =
  PageControl.getUnlimitedInstance(); // gulp - I assume we can fit all package versions in mem

It’s been a while since I’ve come across code that talks to me. Even longer since I’ve seen code emote to me. The good news is that, so far at least, we haven’t had an issue with package versions in memory.

any joy on reproducing?

I sit in a number of non-Spacewalk/Satellite chat rooms at work. This was just seen in a conversation in one of those rooms discussing… well, to be honest, I don’t actually care what bug they were talking about. Taken out of context is way funnier.

...
// Now we filter out an 
List retval = new LinkedList();
...

Shit. Ok, so it’s not too much code after that to see what the filtering is doing, but the comment still left me hanging. :)

1
2
3
4
5
6
7
8
9
try {
    String line = input.readLine();
    while (line != null) {
        line = input.readLine();
    }
}
catch (IOException ioe) {
    logger.debug("IOException...really need better handling here");
}

Everyone, at one point or another, is guilty for just swallowing an exception. Java tends to be a bit trigger happy with its checked exceptions (especially in the IO packages), so it’s inevitable to be in a position of having to deal with an exception that admittedly will probably not happen while trying to get something else accomplished.

The nice part is that I’m cleaning this up and actually providing the better handling. The cool part is that I’m using code I wrote for CodeTurtle to do it. :)

1
2
// why can't I just pass in a dictionary? sigh, there are
// times where python would make this SOOOO much easier.

To give this some context, this was seen above a manual population of attributes in a bean from a map.

I don’t really have any witty comment on this one. There are definitely times where one language would be nicer than another, so I’m in no way saying the comment is incorrect in any way. It just usually makes me laugh to find conversational comments like this, as if you could actually hear the developer sigh when typing out the wordy bean copying.

Just came across the following:

1
sa.setRemainingTries(new Long(10)); // hmm 10?

Not sure what the issue is with using 10 here, but for some reason it invoked the image of The Thinker.

Comment of the Day: Me

March 26th, 2009

The Spacewalk team doesn’t seem fond of the @author tag on its Java classes. I’ve heard the mentality before… “No one owns the code”… “Everyone should feel able to change it”… “You can find it out who wrote it from the source control system”… and so on.

The last rationale is especially funny to me, since on both projects where this argument was made, the code was moved to a new repository at one point and all history before that date was lost, including the original author.

I personally find the @author tag useful in finding out who to ask about a particular class. Thankfully, the Spacwalk team is pretty good about remembering who is an expert on what and I’ve never had an issue. So despite my objections, I’m fine with not using @author tags.

Then I come across this nugget in our codebase…

1
// /me wonders if this shouldn't be part of the query.

The /me is actually the way to emote in IRC. It is basically used to indicate you’re “doing” something rather than saying something as in a normal chat. So syntactically, I’m not confused by why the comment is phrased that way.

What I did find myself asking, out loud no less, was who the hell “me” is in this particular case.

I’m a huge fan of these sorts of inline comments as I’ve alluded to before. But one thing I forgot to mention was that I often throw my name or ID after the comment for comments that are expressing a concern or a personal belief. That way, if the code comes under review, you can ask the commenter their mentality or if the issue still applies.

Perhaps even more important is the date the comment was made. With as rapidly as things change in most projects, it’s not a surprise that a thought or comment that used to apply no longer applies. Scoping the comment to a particular time frame helps whoever stumbles upon it realize it may not still apply. It can save the next dev a lot of time wondering why a comment is saying to add something that may no longer exist.

Or, perhaps using /me is just meant as a brainwashing technique. I’m going to add a comment /me buys Professor Jay a beer to my next commit to see if it really works. And if it does, I’m enrolling my wife in my class next semester and teaching her to be a programmer.