Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Possible Duplicate:
Humor in Documentation

Throughout my professional career, I have often relied on chatty or humorous comments in source code (or source control commit messages) to help break up the tedium of the day or to convey how I felt about the piece of code I was writing. I have always thought that as long as I kept it out of anything a customer can see, it was ok. Recently, I have wondered if they can be distracting to anyone else working on my code, construed as unprofessional, or offer too much room for interpretation. I've worked at some companies with a strict corporate culture and I have never had to answer for such comments, but I would hate to find out that it was throwing someone else off all this time.

So...acceptable or unprofessional? Should they just be avoided?

And, of course, here are some examples (your examples are welcome as well):

try{
    obj.execute();
}catch(SomeException e){
    //squishy, squishy
}

//pretend you didn't see this...
String password = "bananer$";

//I'm under a lot of pressure. I can configure this later. Dont hate me.
//String fp = "C:\Users\scottpa"
String fp = "/usr/local"

and

Commit Comment: I hate when I forget to format!
share|improve this question

marked as duplicate by GrandmasterB, psr, pdr, kevin cline, DKnight Dec 22 '11 at 6:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

12  
You're either going to get yes or no, and its simply going to depend on the company culture. –  GrandmasterB Dec 21 '11 at 22:32
1  
I rather have the witty banter in the comments rather than in the actual code. Sadly, my predecessor didn't feel the same way, so now I'm stuck with variable names that aren't very clear on what they are actually for BUT provide interesting topics of conversation :( –  Jetti Dec 21 '11 at 22:47
7  
They are acceptable provided they are actually funny. If the author merely thinks they are funny, they are inappropriate. Like this comment. –  psr Dec 21 '11 at 22:47
1  
Reminds me of the Dave.cpp dailyWTF –  Jetti Dec 21 '11 at 22:50
    
Weird that the answers to the other question seem to be the exact opposite of the answers to this one. –  smp7d Dec 22 '11 at 1:07
add comment

10 Answers 10

up vote 9 down vote accepted

It's completely a company culture thing. While it may be acceptable (and even encouraged) if you're working at some startups it may not be the best idea to place a dick joke in the middle of a high frequency trading algorithm.

A good judge of whether the comment may be appropriate or not is to ask yourself if you would say it directly to the face of one of your co-workers or a contractor / new hire who you had never met before.

share|improve this answer
add comment

Yes, this is completely unprofessional. Consider the possibility that the company is up for sale, and the code is audited as part of the due diligence process. This makes the company look like it's full of jokers who don't take things seriously (since anyone auditing the code is unlikely to know the developers involved), and may end up costing money.

share|improve this answer
    
Very good point, I hadn't even considered this –  Jetti Dec 21 '11 at 22:48
    
I too find it totally unprofessional, just like I was appalled at one place I worked where the server names were dirty words. Stuff that is funny to single, male 20somethings is not funny to 50+year-olds who are of the opposite sex. Funny belongs in your personal life not your code. At least it's comments and not error messages, those will invariably popup at the worst time. –  HLGEM Dec 21 '11 at 23:07
17  
I do not agree. To be funny does not mean that you are not taking programming matters seriously. It means that you do it with ease and that you like doing it. It also means that you are probably a creative and communicative person. However, dirty and offensive jokes are not funny. –  Olivier Jacot-Descombes Dec 21 '11 at 23:27
4  
I can't agree with a blanket statement. Chatty and childish comments are unprofessional, but a little bit of humor is perfectly fine in many circumstances. I take pride in my work and am very professional but I sometimes leave funny checkin comments. I see nothing wrong with that, and justbabout every genuinely good programmer I know does it as well. –  Bryan Oakley Dec 21 '11 at 23:56
    
Please note that I am not suggesting that I believe that being funny means one doesn't take programming seriously, but I am rather less sure of the attitude of someone who is conducting an official audit on a code base. –  James McLeod Dec 22 '11 at 0:27
show 4 more comments

Yes, those types of comments are unprofessional. Whether unprofessional comments are acceptable is a completely different question. Used very sparingly, most developers think they are fine, even welcome. Use them too much and you will become an object of scorn for constantly imposing your personality on others when they're trying to get work done. It's like telling a joke in a meeting. One is okay. Constantly joking is not.

You can also have fun in a more professional way. For example, when I needed arbitrary coordinates when I was writing automated tests of military aircraft targeting software, I would use the lat and long of my in-laws' house. It didn't affect the code at all, you wouldn't even know it was a house without looking it up, and if you didn't know whose house that was, you wouldn't get the joke.

share|improve this answer
5  
I thought your example was funny, but I wouldn't mention that to your wife. –  HLGEM Dec 21 '11 at 23:11
10  
Then one day, due to a bizarre sequence of flukes, glitches and screwups, your test co-ordinates get used and a live missile hits your in-laws house and detonates, killing everyone inside. –  Steve314 Dec 22 '11 at 1:31
    
@Steve314, I guess as long as Karl's not visiting, he'll be fine with that :D –  Benjol Dec 22 '11 at 6:41
1  
They've moved since then, so it's all good :-) –  Karl Bielefeldt Dec 22 '11 at 7:38
add comment

Unprofessional. About a decade ago, someone leaked some of the source code for windows out into the filesharing networks, and the code contained a lot of profanity in the comments. The profanity and number of unprofessional remarks caused more of a stink than the leak of the code.

Each company is different, and one I worked at as recent as a year ago was very uptight about what appeared in email. One email to other members of my group contained WTF, and when it somehow got forwarded outside our office, I received nastygrams from VPs in other timezones about my profanity.

share|improve this answer
5  
Profanity is unprofessional, but profanity isn't funny and the question is about funny comments. –  Bryan Oakley Dec 21 '11 at 23:58
add comment

Agree it's unproffesional. I'd add to the other answers that chattt comments don't get maintained. Ie when the code geta changed at some point in the future the comments probably don't. Especially long comments. At tjat point they are misleading, long and tedious.

share|improve this answer
add comment

Well, I put some jokes in my comments sometimes. People seems to accept it well, including clients who contract us for making code for them. There is, however, one exception: if the humor is related to a problem in the code, it is better to avoid it. A client would rise eyebrows for something like:

// Here I applied workaround oriented programming LOL

but would be more comprehensive to something like:

// TODO This piece demands some refactoring

Said that, I believe humor in code can be unprofessional and childish in a good way, reducing stress of coworkers and even customers, if it follows these guidelines.

share|improve this answer
1  
+1 for workaround oriented programming! I did not realize there was a single term that described the development process at my job. –  Mike Dec 22 '11 at 6:56
add comment

As has been said several times yes, it is unprofessional. That said, one of the things that as a maintainer of a good sized bit of other people's code one of the things that I often find myself doing is trying to get into the head of the previous programmers, and 'chatty' comments when I find them are much more useful to getting into that previous coder's mindset than finding /* this is an abstract factory builder for an n-tier delegate */ or /* TODO replace */.

Every minute faster that I can get into the mind of that previous coder is a minute more I can spend fixing or extending. If the previous coder was frustrated when writing the code and blowing off steam, I want to know that. Repeating what the code already says (and especially boilerplate comments telling me that /* Foo controller is a singleton */) don't give one bit of insight into what was going on.

Tech and business design docs (when they exist and can be found) are bland and most often for management rather than the code. They don't explain the influences that happen after the docs have been written (and forgotten). The code and the comments are the mind of the programmer.

Don't write anything you wouldn't want your mother to read, or to have show up on a performance review. Do everything you can to help that person five years down the road to understand what you were thinking at the time.

share|improve this answer
    
Good point. If I see a comment like "I hate myself for resorting to this" in bad code, I will not get as down on the code base as I would. –  smp7d Dec 23 '11 at 14:01
add comment

“What is funny?” has been discussed by philosophers since at least the 4th century BCE. About the only thing agreed is that it has to be audience appropriate. And as written above—software often has an audience that is almost completely unknown.

Humor yields to the hypothetical…

That said, Knuth uses jokes in his code.

Corollary as a piece of code:

def ShouldIPutJokesInMyCode(name): return(name=="Knuth")

Is this funny?—Oh my.

share|improve this answer
3  
int getRandomNumber() { return 4; // chosen by fair dice roll, guaranteed to be random. } –  Bratch Dec 21 '11 at 23:50
    
I think you are wrong (but not enough to downvote). The audience for most software is known -- it's other programmers, fewer QA's, and much fewer managers and bean counters. We're talking about code here, noy interface elements. –  Bryan Oakley Dec 22 '11 at 0:00
    
@BryanOakley — You’ve obviously never worked at a large company nor written a large open source project. You have no idea who is gonna read your code and who is gonna complain about what. Also, I don’t know what you mean by “[we’re] talking about code here, noy [sic] interface elements” either. But I am not sure I care at this point… –  veryfoolish Dec 22 '11 at 3:48
    
@veryfoolish: you are correct; the largest company I ever worked for had only a couple thousand people. Most of the companies I've worked for were 150 people or less. But depending on your definition of "large", I've worked on a largeish open source program or two. As for the interface elements comment, I was referring to the fact that the audience is other programmers. If we were talking about user interface elements, the audience would be the users of the software which are typically a different sort of person. –  Bryan Oakley Dec 29 '11 at 2:02
add comment

Please don't do it. At least, not if I'm ever going to have to read your source code.

If I'm trying to understand someone else's source code, I read the comments to garner information. Any text that doesn't give me useful information is wasting my time, and has no place being in the source code.

If I want to read jokes while I'm at work, there are plenty of other ways for me to achieve that.

share|improve this answer
add comment

There are situations where it is acceptable, but you should take care. If you google up source codes, it is very common to find these. This one is in the android source code:

/* now check out who it is.  We don't care about mismatched DNS names here,
   but any ADDR and PORT we specified had better fucking well match the caller.
   Converting from addr to inet_ntoa and back again is a bit of a kludge, but
   gethostpoop wants a string and there's much gnarlier code out there already,
   so I don't feel bad.

But If I look to someone else code, I would determine if it is professional or not, not by evaluating the comments, but mainly by evaluating in what point it is in a scale comming from "utter big ball of crap" and "the most ellegant and well-written code I already seen".

To this comes variable and function names; proper use of the OO, functional or whatever relevant pradigm applies to the language; API design; simplicity; elegancy; proper reuse of existing code, etc. If everyone of these is very good, the code is undoubtful very professional even if its comments are not.

The opposite is true too. I personally already saw a horrible behemoth of something like 5000 lines full of code duplication, global vars, variables with random names, without any recogniable structure. The purpose was to parse a date and determine if it was valid or not. To make things worse, it accepted some invalid inputs and rejected some valid ones. Some inputs made it crHowever it was very well documented. So, even if the comments are very professional, I still think that the world would be better if someone killed the author of such horror.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.