My Goal: Naive Programming
I want to be able to program naively.
Elegant code in most languages, is very often considered naive. The most natural, compact, and precise way to express an algorithm is often inefficient. I want to write algorithms, not code. When I write algorithms in some language, very often the resulting code is criticized as sub-optimal, or perhaps the worst insult of all, it is “naive”.
Think about this, after 25 years of writing computer programs in over a dozen languages when I write code in a language that I am not fluent in, the code I write is usually considered naive. You are probably thinking “So what? Maybe you are a mediochre programmer, besides, to use a language you need to spend some time familarizing yourself with the idioms of the language”. Maybe I am mediochre, but after studying so many languages I’ve realized almost all programming languages are the same: “iterate”, “branch”, “define function”, “apply function”, “make collection”, “input/output”, “store intermediate result” and maybe if you are lucky “define module”. After enough experience moving between languages you stop thinking about idioms and syntax, and start thinking in terms of algorithms and abstractions.
So what motivates most programming idioms? Efficiency and safety. Now what does that have to say about a language? It indicates very clearly that the language has a problem, the most elegant or natural way to write some type of code is not the most efficient or safe. Time to start reexamining your language and compiler I’d suggest.
In whatever language I happen to be using I try to write code where it is obvious what the input is, what the output is, what the requirements are, and what the transformation is. I don’t like to think about function inlining, intermediate results, result caching, tail-call optimization, or any of that silliness. This just obfuscates the intent of my program and should be transformed by a compiler. However, what I call elegant code is too often considered “naive”, because a particular language implementations can’t figure out how to transform lucid code into efficient code.
I don’t care if call my code naive, just make sure your language implementation can deal with it.
PS: I’ve followed this up with a new post about naive programming containing some code examples.
[…] was happy to see some pretty engaged discussion at Reddit about my recent blog post about Naive Programming. What was most clearly lacking in my original post were some examples, so I’ve included a […]
Pingback by cdiggins.com » Naive Programming Follow-Up — July 2, 2007 @ 6:09 pm
[…] Diggins on Naive Programming: So what motivates most programming idioms? Efficiency and safety. Now what does that […]
Pingback by Chipping the web - Sterling -- Chip’s Quips — July 4, 2007 @ 10:50 pm
[…] Jul 2nd, 2007 by hanxiaogang See this post: […]
Pingback by Naive Programming ? Naive Programming ! « Try your best, man — July 18, 2007 @ 3:21 pm