A friend of mine told me about an experience he had in one of his programming classes. I found it funny, so I thought I would share it here.
Programming joke of the day; this actually happened to me:
We have a little program we need to run on our code called "Checkstyle" that goes through our code to find anything stylistically wrong with it. If it doesn't pass check style, we can't get credit on it. Sometimes, it takes issue with stuff that really shouldn't (in my opinion) be an issue.
Today, it spat out a bunch of error messages telling me that some of my lines of code were more than 100 characters long. I said "Are you kidding me? We aren't allowed to have lines of code longer than 100 characters?"
A haughty T.A. passing by said "Of course. Checkstyle likes readable code. It's more professional."
A person sitting next to me said "Hey, if your line is too long, try taking out the 'space' characters between your operators and your operands. They aren't needed to compile anyway."
I said "Great Idea! That'll cut down the line size, which makes it more readable, right?"
Somebody else suggested "Are your variable names too long?"
I said "Yeah, probably. I'll global search and replace them into names that are only one character long. That should help too."
After looking at my code, I found that the issue was my error message. My error message was about 60 characters long, politely informing that the only legal strings allowed in the method are "heads" and "tails". I replaced the error message with a frowny face emoticon instead.
After putting the finishing touches on my code, I ran it through checkstyle. It passed. I got 102% on the lab. I'm so glad they gave me such a wonderful tool to make my code more professional and readable!
Along a similar vein, checkstyle doesn't like "magic numbers." In one lab, it told me that "4" was a magic number, and needed to be replaced. In class, somebody commented on it. "What is a magic number, and how do you avoid using them?"
The teacher said "A magic number is a number in the code that is there for no apparent reason, but makes the program work right. Typically, you should replace them with global variables. Like, can anybody tell me how to handle the magic number '4' in the first lab?"
I raised my hand.
"Well, '1' isn't considered a magic number, so just replace all instances of '4' with '(1+1+1+1)."
The entire class laughed. Including the teacher.
"Just in case you were wondering," he added, "that was not the right answer."