1. Sep 18th, 2006

    Take the quiz: how elegant is your code?

    Computers have an acute sense of aesthetics. Yes, even the Dells. They simply refuse to run ugly code, which is why to succeed in this business you must be an elegant coder.

    So you’re the coding convention Nazi that reviews other people’s indentations. Your IDE is setup with templates and style checks. You can argue brace placement with the best of them, and own two copies of “Spaghetti is a dish, not a design pattern”. But how can you tell if your code is elegant or not?

    Unfortunately you can’t. Elegance is “I’ll know it when I see it”. But you can identify inelegant code. So as a service to the community, I’m offering this guideline to calculate an inelegance score for your code. Let’s see how you measure up!

    • Other people’s code Add one point for any piece of code written by someone else. Add another point if they use the wrong IDE, run the wrong operating system, or don’t watch Battlestar Galactica.
    • Your old code Add one point for any piece of code you wrote 6 months ago. Add another point for any piece of code older than your iPod, that you now have to “maintain”.
    • Open sourced Add one point if anyone else touched your code. One-line changes don’t count. Add two points if the same function uses iterators and recursion, and you can tell who wrote what part.
    • Value system Add one point for every string manipulation written in Java; one point for every Perl code pretending to be a framework; one point for every bash script written by an ex-Windows developer; one point for every UI written by a Vim user.
    • Death march No points for code written early in the project, one point for every piece of code written close to deadline, and a fraction of a point for anything in-between. Add an extra point for every piece of code written after the planned ship date, two if you’re a startup.
    • Outsourced Add one point for every piece of code written by a consultant, two points if they’re considered an “expert” in their field.

    Now tally the results:

    • 0-3 Congratulations, your code is as elegant as Windows Vista! And will take as long to ship.
    • 4-7 Indenting with tabs and spaces! Didn’t your mother teach you anything?
    • 8-11 Everytime you commit a change, God kills a kitten.
    • 12-14 Let’s start with the basics: pants are worn below the belly and socks belong inside shoes.

    Photo by toppy_knots.

    1. Sep 20th, 2006

      apotheon

      In short:
      Nobody writes elegant code.

      Is that it?

    2. Sep 20th, 2006

      Assaf

      You know the saying, “the best code is the one you don’t write”. It has no security issues or performance overhead, easy to troubleshoot and maintain. It’s full of elegance without the flaws!

    3. Dec 17th, 2006

      Chipping the web – “a funny number” — Chip’s Quips

      [...] Joel decides to supplement the discussion on simplicity with a “new” term: elegance. Hmm, seems like I’ve heard that one somewhere before, only it didn’t have much to do with avoiding “intrusion into the user’s actual DNA-replication goals”. [...]

    Your comment, here ⇓