Can we have fun in code?

my take on humors in code

7/1/2018Time to read: 4 min

There is an old article titling We Are Morons: a quick look at the Win2k source published in 2004 by Selznak. It presents some interesting code comments inside the source code of Windows 2000.

For example, here is one from the article:

 *       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 *       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 *       !!!!!!!!!!!!!!DOING SO FUCKS THE BUILD PROCESS!!!!!!!!!!!!!!!!
 *       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 *       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I think every programmer can relate to those comments, and sympathize with the struggle of Microsoft developers. But as an outsider, those comments also feel very funny. I can't stop laughing looking at those comments.

But does that means we are evil? laughing at other people's struggle? no, the code is for Windows 2000, which hopefully nobody would need to develop anymore.

Mark Twain said:

Humor is tragedy plus time

I think this quote well explains that.

The human mind has a very special logic in determining what is funny and what is not. There is a great TED talk giving by Peter McGraw on What makes thing funny. In short, he concludes, that, humor is a benign violation. For something to be funny, it needs to satisfy two criteria:

  1. It needs to be a violation. It could be a violation of the norm, violation of value, etc.
  2. It needs to be benign. If the violation actually caused harm, it won't be funny anymore.

When your friend trips, you might feel funny, because it's a violation, and tripping normally won't cause any harm. When your friend got hit by a car, that is not funny at all, that's a serious issue.

With those principles, I start to think about, what we can do to incorporate humor into coding.

Why do we want to do that? It's perfectly fine to write plain, standard code that doesn't use any humor. Any even, our bosses might be happier if we don't spend ten minutes thinking about a joke to use in the enterprise code base.

But I want to argue that, sprinkling some humor into code has benefits.

It makes reading the code more enjoyable. We all know writing code is simpler than reading code. The writer has the whole system design in the head, while the poor reader needs to pick up different parts of the code one by one. Readers need to have a good memory, when they digest a chunk of code, they need to connect to the other parts of the code that they have read. Humor can strengthen memory. If you are working on an important component of a system, adding some humor to it will make it more memorable.

It softens the burden of a programmer. say you implemented a complex hack because you have no other choice. The next poor developer working on it will feel relatable and less stressful if you have added some humor.

Overall, a codebase with humor just makes it more fun to work with. After all, programmers are all human beings with emotions.

But on the other hand, our software code is a very serious business document. If we make a mistake because of a joke in code, it's unforgivable. So we need to be very careful about how to use humor in code.

Naming variable names funny, but inaccurate names is a big no-no. Naming things is one of the hardest things in computer science, so might as well be serious about it.

Structuring the code to look like a Christmas tree is also inappropriate. If we are sacrificing something, either readability or performance, just for the funny effect, it's not worth it.

Adding unrelated comments is a bad choice too. It distracts the readers. I think most people would rather read jokes online than in the comments.

Too many jokes are boring. Using the same joke multiple times is also boring.

Seems like using humor in code in a lot stricter. We want to make sure our humor is benign because any harm caused by our joke would be frown upon, both by our fellow developers and management. So ... can we still use humor in code?

We surely can.

My code worker did a presentation on the dynamic layout system of our app. He found a bunch of stock photos of human expressions, and he showed that, with different parameters, the layout system was able to display different pictures. I think this is a great example of using humor in code. Our application is a serious enterprise app, but it doesn't harm to show some smiley faces when demoing. Generalizing this idea, I think using humor when we are demonstrating something is very useful. Things like documentation, test cases are both good places for some humor.

For example, below is a test case:

describe('findSubstrings', function () {
  test('should find substrings that are overlaping', function () {
    const substringIndices = fingSubstrings('abababa', 'aba');

There is nothing wrong with this test case. It's clear, concise, and demonstrates the contract of findSubstrings function. But wouldn't it be more interesting if it is written as:

describe('findSubstrings', function () {
  test('should find substrings that are overlaping', function () {
    const substringIndices = fingSubstrings('NANANANA BATMAN!', 'NANA');

Comments are some a good place for humor when we are documenting some hacks, as long as we don't use swear words :)

We can also use humor in places that are not very important. Our team doesn't use git commit messages for anything other than linking to the issue. Some people just use issue number as the commit message. I worked on a bug in our website caused by a Chrome regression. I could have given a plain message, like "ISSUE 32 implemented a fix for Chrome", instead I typed "ISSUE 32 Chrome broke everything". Later my code reviewer told me he really enjoyed it.

I think using humor in code means the developer is passionate about the code. Like a craftsman, developers embed their emotions into the humor, which liven up the codebase. Humor is a good thing to have in code, as long as we are doing it right.

Can CSS Modules solve all the problems?
Why we should use Storybook for UI development