3 ms·
Yegge says that novices don't like his second example. But I've been paid to maintain compilers written in Lisp, by people who've hacked in Lisp for decades, an
by ekidd 15y ago
Yegge says that novices don't like his second example. But I've been paid to maintain compilers written in Lisp, by people who've hacked in Lisp for decades, and I don't like it either: The "compressed" code example is not awful, but it's not a good example.
An expert should make things clear, even if only to other experts.
Basically, that function is too big, and it uses too many mutable variables. I had to stare at the control flow for 'destructuring' and 'init' for over a minute before I convinced myself that it actually worked correctly. More often than not, a deeply nested Lisp function with mutable variables will contain subtle bugs. So when I see something like this, I need to slow way down and take nothing on trust.
Here are two ultra-compressed parsers that I like better than Yegge's:
https://gist.github.com/1068185 https://gist.github.com/1068185 and
http://book.realworldhaskell.org/read/using-parsec.html http://book.realworldhaskell.org/read/using-parsec.html
To understand these, you'll need some specialized knowledge. But once you understand Yacc (or Parsec), this code is straightforward and clear. The structure of the code mimics the structure of the problem.
- ajross 15y agoOK, but you're criticizing his example from a functional perspective. You want to see something more scheme-like I guess (and frankly I'd agree). But that's not about metadata density, which is the point of his blog post.
- prof_hobart 15y agoThe two are related though - I very sparsely comment my code these days, but I cam do this partly because I break my code down into small self-describing functions with meaningful names.
- calebmpeterson 15y ago> Basically, that function is too big, and it uses too many mutable variables. An interesting statement that; particularly the part about mutable variables. Mutability implies state, and state seems to be something we, as programmers, often struggle with. Keeping the those state transitions within our mental model seems to be the hard part. I've been studying Clojure a lot over the past 12 months; it's approach is quite different from the 9-to-5 Java I write. Rich Hickey's notion of disentangling state into value and identity has been so very helpful to me in dealing with the 'problem' of mutability and state transitions in how I write my own code. Lisp, whatever the dialect, doesn't strike me as the sort of thing that most Java shops (particularly the large corporate variety) are going to swallow, but the ideas of Clojure... Perhaps I need to get out more, but it's the only language I've seen that proudly embraces a deeply functional paradigm without punting on State (or destroying my brain with monads). I have no deep love for Java, but once Java 8 arrives with lambdas, all I'll really want is a good implementation of persistent data structures. PS nothing against monads (or Haskell) - I just haven't gotten there in my Perlis journey.