Ask HN: Do you swear in your code?

15 points by blang ↗ HN
At my company, there tends to be some bad language in our code base. It's pretty common place to find F bombs in they comments. Is this normal practice?

81 comments

[ 4.3 ms ] story [ 161 ms ] thread
i did in college, and also frequently used "TAMO" in comments

but then i joined a company that supplies source to customers.

Swearing in comments is unacceptable IMO. You wouldn't write swear words in internal documents, so why do it in code. It's unprofessional and shows a level of dis-respect for your own code and for the people who might end up maintaining it. Plus, heaven forbid a client happened to see it as well.
You work in a corporate environment don't you. You had to fill out a "comment request form" in triplicate just to post the above comment ;)

I'd say it depends. If you're working for bigco, swearing is probably not going to go down well with your boss, or co-workers. If you're working in a startup/open source project/on your own, then swearing can be good and useful IMHO.

If I swear in the comments of some code (Rare), I can instantly see that I've had some issues with that code, or something I'm interfacing to is idiotic and needs fixing etc.

You work in a corporate environment don't you. You had to fill out a "comment request form" in triplicate just to post the above comment

You don't work in a corporate environment, do you?

If you're working for bigco, swearing is probably not going to go down well with your boss, or co-workers

Since few bigcos I've ever worked at ever do code reviews, how would they even know?

After spending many years in corporate environments, it's easy to spot those who haven't when they post comments about corporate environments.

My last job was in a corporate cubedom for 4 years. Not a massive company, but a few 100s of employees. We held weekly code reviews at one point. Also bosses do have a habit of suddenly believing that if they help code the project might run quicker, so they ask for svn access etc, then break everything :)
So you have worked in a corporate environment. My mistake.

But tell me, when did you ever have to fill out a "comment request form" in triplicate?

Now I can't work out if you're being sarcastic or not.
Touche.

I've worked in many corporate environments, some where things were perfectly logical and others that aspired to be as good as Dilbert.

But I never had to fill out anything in triplicate. I guess I should have realized the sarcastic flag was up. Sorry.

We had so much Sarbanes-Oxley bs anything seemed possible. "Oh you can't use an IM client that isn't approved by us, as it's against S-OX". (Approved by us meant that they paid some inferior crappy IM company to install their client on all company computers. Then they paid a fee per user) Nothing like corporate waste :)
We aren't building tractors, we're "painting" software and do whatever makes us feel more creative. In fact some really great hackers I knew were very passionate about their code and coding process in general. Once we had a dedicated Yellow Pages book to throw in a brick wall (literally). That was awesome.

BTW, didn't you notice how often good programmers curse in public?

I suspect we work in different industries.

You think people who build tractors don't swear? After my work in steel manufacturing, I would bet that there is some informal manual next to a machine that has at least one swear word in it.
True story: During a summer internship years ago, I used Foo and Bar as placeholders throughout a web page comp. My boss sat me down for a serious chat about professionalism. Turns out he had never heard of Foo and Bar. Prior to that conversation, I had never heard of FUBAR.
Yes, that's the source of the symbols. Some people like them, some think they're unprofessional, yada yada. But I've never once had someone try to interpret "foo" as profanity...
I think that's where FOO and BAR come from.
I've heard more than one hacker speak about either ignoring or redefining "professionalism" (whatever that means):

JWZ: "I wear my unprofessionalism as a badge of honor." <http://www.jwz.org/doc/easter-eggs.html>;

PG: "Maybe some aspects of professionalism are actually a net lose" <http://www.paulgraham.com/opensource.html>;

PG*: "the way that he thought about professionalism did not differ from the thinking of a Mary Kay cosmetics saleswoman: wear nice clothes, drive a clean car, and don't say anything that might offend anyone" <http://philip.greenspun.com/ancient-history/professionalism-...;

We speak and write profanity in other contexts, so why not code? It shows respect for future maintainers that we're honest about what truly sucks, instead of watering it down. Plus, we don't care if clients or investors see that we don't wear suits (or even shoes); similarly, they care about what the code does, not what it looks like.

One interesting compiler bug later and your comment could end up in an error message.

Anyway I would only swear when I'm at home with a beer in my hand, so I only put swearwords in my code when I'm working at home with a beer in my hand ;)

I think people have mis-understood my comment. I never said swearing was bad. Practically every word that comes out my mouth is a swear word. I just don't think swear words in code makes for "beautiful" work. I even have a go at developers for not putting full stops at the end of comments ;)

In addition, it's got nothing to do with working for a large corporation as I work for a small advertising software company with less then twenty employees.

I'm located in the northern parts of Europe so perhaps that explains it but I routinely and deliberately use foul language in technically oriented internal documents. The rationale being that it should be harder to copy'n'paste and edit it in an ad hoc sales doc than to ask me for a more specific technical explanation.
Always assume that what you write is read by others than you intended. That goes for code, documents, emails, and test data.
It is a fairly common practice. That being said, it's a bad idea to allow that to stand in your code base. It never adds anything to the clarity of the code, other than the fact that you now know the developer writing it has a bad temper.

While you're in there cutting out F-bombs, you should probably do yourself a favor and review the surrounding code. Foul language in comments are almost always put in out of frustration, so you probably have some good targets for code refactoring.

It's OK to do it in C++, if you must. It's very, very stupid to do it in HTML...
Seen more than once where a site was blocked by a filter because someone cursed in the comments. Page looked perfectly clean otherwise.
Fuck yes it is.
Addenda: is this perhaps the dumbest fucking question to be asked on this board? Fuckin' A right it is. Can someone draw a line between this topic and something that actually matters to a startup?
if it doesn't matter, why reply?
You might ask yourself the same.
I replied to you because I was curious what you'd say. I am interested in human psychology.
And you have confirmed how easy it is to bait me into snarky responses. Congratulations!
Why are you getting snarky? I was perfectly serious. I think it's best to ignore silly things. Most people seem to give them a lot of attention. That's important. I want to know why they do that.

Possibly related, many people I know find it easier to think of things to say in reply to stuff that's mistaken than in reply to stuff that's accurate. So they spend more time engaging with mistakes than thinking about the good ideas they encounter. That's important too.

Oh. I replied because it was fun to do so, and because I'm in an epic bout of procrastination.
Sometimes, but usually only in code I'm using to wrap my head around a new concept that I'm struggling with. I generally don't swear in code that's going live, or public at all.
Some people don't quite get the message unless you use swear words. Especially when the message is "this code is used to be compatible with X, and IMO, X is not very good". 'Not very good' doesn't really describe the emotion that it gives you. I'm sure there's probably better ways to criticize another software system, but when you're short on time, sometimes swearing does the trick. Most often I've deleted such comments or re-written it with a more eloquent vocabulary. But in general, I don't think it's forbidden territory. Call it being passionate about your craft :)
I don't have a habit of commenting stuff, so i do it rarely. I don't write allot of unclear code(tanks to python) so i don't have a lot of places to express myself in any other form but good code. I comment only hairy stuff. But i use swear words as a variable names sometimes if im not going to show the code to others, but they are usually not in English.
No. Aside from the fact it's unprofessional, it makes you look amateurish if the code ever ends up public. This happened with some YouTube code last year, if I remember correctly, and that is exactly what it made me think.
Better code than you will ever write was written by people who swear a ton. Strange how that is.
Fuck yes!

Just like the pros: http://www.jwz.org/doc/censorzilla.html

I would say that's classless, engineering arrogance at best... there are better ways to flaunt intellect and respect, like by owning a night club.
There's swearing in comments, then there's:

  cmd/xfe/editordialogs.c:   fuck = fe_file_name_int_my_directory(context, buf, link_text);
  cmd/xfe/editordialogs.c:   if (fuck && fuck[0] != '\0') {
I wouldn't follow their example. Netscape Communicator was a big pile of shit.
It is ok as long as only friends read it, "Haha, look, Johnny used a swear-word, he's such a witty guy" they'll say. But there may come a day that someone who doesn't know you reads that comment, without knowing you and your colorful personality and reading it completely out of context her first impression of you will be that you're a cantankerous old fart and she'll hook up with that dumb html-"programmer" instead.
The only F word I ever see in my company's code base is FIXME.
Do I swear under my breath when code doesn't run how I meant? Often.

Do I sometimes put dire warnings or florid descriptions of suckage or even rhyming couplets in my code? Yes.

Do I swear in code? No. Swearing is easy and imprecise. If I can't find a more useful way to convey my point, I'm obviously not firing on all cylinders and should take a break.

To be fair, nearly everything I work on is one or both of at least moderately interesting or for a good client. If I were working on something obnoxious for a boss I disliked, maybe I would swear. But even then I'd be more inclined to sarcasm.

(comment deleted)
This is as close as I come, a comment from a few days ago:

> <%# All acesss to the message bar should go through the message()

> function defined above or kittens will be harmed %>

// No fucking clue why the below line is there
Yeah, comments in my code are "notes to self" as much as anything. When I come back, I want to know what I was thinking. If I've commented like that it means I've thought about it and drawn a conclusion, rather than just skipped it as unimportant.
the only profanities in my code are throw and raise
You know how some people swear casually, while others would cringe in shame if the apocalypse happened and a curse word passed their mouth?

Same for when they're writing code.

I don't quite get the shocked reactions.. I can understand thinking swearing is distasteful in certain contexts but would certainly never draw wider conclusions about a person because they swear. Then again, I'm Australian.

abso-fucking-lutely
I used to ... until about 8 years ago when I response.write'd a large "FUCK YOU" in an asp app that I forgot to take out.

A big honkin' "FUCK YOU" that showed up during QA 5 minutes before client showed up for review.

Never again.

This is exactly why I don't put curse words in code, even in comments. This stuff really does happen, and the results can be awkward. It just isn't worth it.
I work in post-production graphics, and when troubleshooting particularly nasty problems I've been know to name some of my project assets things like "WhattheHelliswrong.mov"

I would not recommend doing this, but it definitely made me feel better.

When /fuck doesn't find anything, I know my code is ready for 1.0