Sunday, January 12, 2014

Functionally semi-literate?

Huh.

I'm slowly coming to the conclusion that humans have an amazing ability to adapt and change, and to be completely ignorant of those changes.

As far as the inside of my brain can tell, I am pretty much the same guy as I was in my college years.  If anything, I assume that my brain power was a little higher back then - I am 56 after all - but aside from being a little less able to focus intensely, I think I'm approximately as smart as I was 30 years ago.

A couple of things have happened in recent years which suggest I might be wrong.

Thing #1: In my college days, I tried and tried to get into Knuth's "The Art of Computer Programming".  But there was something about his writing style that made the material rather opaque to me.  Partly the insane MIX machine, but also ... I don't know ... a certain arrogance.  At least that's the conclusion I came to, and I've harbored a secret resentment towards Knuth ever since.

Imagine my surprise when, on a lark a couple of years ago, I picked up one of the volumes and started reading it.  Whoa!  Did somebody replace those impenetrable tomes with clear and concise writing?  And the arrogance, where did it go?  What I saw instead was a wry sense of humor which made it enjoyable to read.  I'm officially a fan.

After thinking long and hard about it, I've tentatively concluded that, yes I had some trouble with the material in college, and I became unconsciously defensive, blaming the writing for my difficulty.  But that leaves the question: why am I able to digest the material with relative ease now?

Thing #2: Also in my college days, I wanted to learn LISP.  So I got Winston and Horn and started in.  And although I was able to get the basic syntax, I didn't *get* it.  I couldn't understand the point of so-called "functional programming" where sequential execution is eschewed.  No side effects?  Immutable variables?  How could you write anything more complicated than towers of Hanoi?

I decided that I just didn't have a functional brain - I was brought up imperatively, and my brain was set.  No way I could "think" functionally.

Then, a little while ago, XKCD had a comic about Haskell, a functional programming language.  I looked in the forum and saw the same old religious wars as always between functional and imperative.  One of the posts mentioned a Haskell tutorial, "Learn You a Haskell for Great Good!"  The silly title piqued my interest and I looked it over.

Well, slap my ass and call me Sally!  Imperative programs consist of telling the compiler how to execute an algorithm, functional programming consists of defining what the algorithm IS, it's definition!  Imperative is dynamic: you DO step 1, then you DO step 2.  Functional is static: you define a function's outputs in terms of its inputs, and let the compiler figure out how to evaluate it.

OK, all you imperative programmers probably didn't experience a blinding flash of insight by that paragraph.  (Go through the Haskell tutorial - it's really good.)  But basically, the tutorial disintegrated a little rock which had gotten stuck in my mental gears all those years ago.  Why hadn't anybody said it that way back then?

But LISP, now that's another story.  Between car, crd, cons, and lambdas, I just don't have the brain for it.  But I checked a LISP tutorial (not nearly as good as the Haskell one) and within about 30 minutes I got it.  I'm not a LISP (or Haskell) programmer by any means, but now I *get* them.

Without intending to detract from that great tutorial, I suspect that the biggest difference between "college me" and "now me" is my own lump of grey matter.  30 years of experiences (both technical and otherwise), 30 years of exploring other points of view, of having my mind expanded by continuing to learn the craft, 30 years of ... dare I say it ... getting smarter.

It is still true that I can't focus as intensely as I used to be able to do.  But maybe there is some truth in the tired old saw that geezers like me may not be able to put in hours like a 20-something-year-old, but the hours we do put in might be better spent.