Self-documenting code contest

There’s a really neat contest going on as a response to the Obfuscated C contest. The goal is to write a piece of code that solves a particular problem in such a lucid manner that, without comments, lay people would understand your solution. The problem:

Write a program that generates all two-word anagrams of the string “documenting”. Here’s a word list you might want to use: http://pragdave.pragprog.com/data/wordlist.txt.

This Python one-liner is a sufficient solution (isn’t it ironic that the rules of the self-documenting code contest are under-specified?):

[(word1, word2) for word1 in wordList for word2 in wordList]

More seriously, here’s my beautiful Haskell solution. Haskell can be very clean, concise, and elegant if you know the rules, but I’m pretty sure the list comprehensions and higher-order functions would confound the uninitiated.

2 Comments

  • Hi David,
    Thanks for your comment on my blog: http://techismything.blogspot.com/. I’ve removed the article that you were offended by, and want to clear up that the article ‘Appreciating Windows’.

    Please have a look at my latest post, to clear up just what I meant. I didn’t have the intention of crediting anyone else for your hard work.

    Thanks,
    Danny

  • I agree your Haskell code (and Python snippet) is the epitome of pithiness!

    Nevertheless, I came up with a solution that I feel is a bit more “self-documenting” in the spirit of the original challenge — e.g.: that a lay person could read the code and understand what’s going on.

    I’ve posted it at:

    http://revuser.com/readable.htm

Leave a Reply