The Parable

You’re writing a class to connect to your company’s application. You and your colleagues all agree that the feature this class is for is the coolest thing you’ve ever heard of – it’s the “bees knees,” one of your colleagues keeps jesting.

Next thing you know, the driver of you mobbing session renames the class to the_bees_knees. Everyone giggles and moves on to working on other parts of the code base.

Unbeknownst to them all, they all just became accomplices in a crime yet to be committed. Five years later, a new developer at the company committed several instances of murder. When he was caught and confessed, his reasoning was “I was thrown into an uncontrollable rage while refactoring code because someone thought the_bees_knees was a good thing to name their class.”

The Moral

The above is obviously satire, but it is grounded in reality, since I had to deal with a class named the_bees_knees only a few weeks ago. The moral of the story certainly sounds like “Easter Eggs are bad,” but what really is an Easter Egg, and what kind of Easter Egg are we talking about here?

Merriam-Webster defines an Easter Egg as “a hidden feature in a commercially released product.” In most cases, this describes a Consumer-facing Easter Egg, since these features are included in the product in order to entertain customers. However, this same definition can apply to what I define as a Developer-facing Easter Egg. The difference is in the bold words from above:

  • product: The code itself is the product that is being given to other employees.
  • commercial: The code itself is commercial in the sense that it is a product given to other employees to maintain.
  • hidden feature: The code can contain features that only the programmer can see. Some examples include ASCII art in comments, or strings that contain references to cult-classic movies.

Customer-facing Easter Eggs are absolutely fine, since they add value to the product that you’re creating. Dedicated fans can find these Easter Eggs and be entertained by them. At best, Developer facing Easter Eggs add value to the code in a non-optimal way, and at worst, their existence makes the code more unmaintainable.

Therefore, I claim the moral of the story is the following:

Developer-facing Easter Eggs in your codebase are never okay. Developer-facing Easter Eggs are an easily avoidable, existential threat to the maintainability of your code, with the only benefit being the potential of a few laughs from your coworkers.

A few examples of developer-facing Easter Eggs:

  • Naming a class the_bees_knees
    • Completely non-descriptive of the class’s purpose. How is anyone who inherits this code supposed to understand it?
  • ASCII art in comments
    • What purpose does this serve? The one case I can think of is if your code generates ASCII art, and the comment describes what the code is supposed to produce.
  • A movie quote as the string input of a function for a unit test
    • While this example is not as bad as the previous ones, it is still bad because the string could be more descriptive for the purpose of the test. For example, if you want the test to fail with an exception, the string “BAD STRING” could suffice.
  • “Meme numbers” in unit tests (420, 1337, etc.)
    • Again, not a terrible Easter egg to have, but you run the risk of limiting what your test suite tests if you use these numbers all over the place. If you are to use these numbers as inputs to a function like they’re “some random number,” then ensure you use them sparingly.

If your goal is to make code that makes other programmers laugh, then by all means add developer-facing Easter Eggs into your code. Otherwise, you should recognize that your code is a product, and its selling point to your coworkers is its functionality and maintainability – not how many inside jokes you can stuff inside of it.

…but does this really matter?

In a world with null-pointer exceptions and multi-threading race conditions, maybe focussing on the miniscule downsides of an Easter Egg is a foolish endeavor. Does it make sense to spend a week refactoring all of your code to remove strings that might have movie quotes in them? I’m definitely not suggesting that, and I think you’d be hard-pressed to find anyone who thinks doing that is worthwhile.

You might have even considered that adding Easter Eggs detracts from the monotony of your job, which is something we all need from time to time. As long as you use proper precautions to ensure your code is still understandable, then I can understand why you’d think this.

Adding Easter Eggs is a risk-benefit analysis. Hopefully this post provided you with a different perspective on Easter Eggs. I personally have decided that the risk is never worth the benefit, but you can come to your own conclusions.

EDIT: A Counterexample

A friend brought up a great counterexample after posting this:

            uuuuuuuuuuuuuuuuuuuu
          u" uuuuuuuuuuuuuuuuuu "u
        u" u$$$$$$$$$$$$$$$$$$$$u "u
      u" u$$$$$$$$$$$$$$$$$$$$$$$$u "u
    u" u$$$$$$$$$$$$$$$$$$$$$$$$$$$$u "u
  u" u$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$u "u
u" u$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$u "u
$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $
$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $
$ $$$" ... "$...  ...$" ... "$$$  ... "$$$ $
$ $$$u `"$$$$$$$  $$$  $$$$$  $$  $$$  $$$ $
$ $$$$$$uu "$$$$  $$$  $$$$$  $$  """ u$$$ $
$ $$$""$$$  $$$$  $$$u "$$$" u$$  $$$$$$$$ $
$ $$$$....,$$$$$..$$$$$....,$$$$..$$$$$$$$ $
$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $
"u "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" u"
  "u "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" u"
    "u "$$$$$$$$$$$$$$$$$$$$$$$$$$$$" u"
      "u "$$$$$$$$$$$$$$$$$$$$$$$$" u"
        "u "$$$$$$$$$$$$$$$$$$$$" u"
          "u """""""""""""""""" u"
            """"""""""""""""""""

DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING. IF YOU ARE UNSURE, CONTACT FOO@BAR.BAZ

This ASCII art is an Easter Egg in the sense that its an over the top, hidden feature of the code, but the fact that its such a striking and obtuse image is actually a big benefit. It’s an eye-catcher, which is exactly what you want to ensure people don’t edit this file if they don’t know what they’re doing. Sure, you could make this catch eyes with less work, but this ASCII art ensures that it’ll make people stop in their tracks.

This is a great usage of an Easter Egg. Do this.