Friday, August 17, 2007

One-Line Code Snippets Allow You To Avoid Useless Knowledge

Why the Lucky Stiff made an interesting post about the value of code one-liners in learning a new language. I'd take it one step further, and add that one-liners and similar tiny snippets are valuable because they allow you to skip learning parts of a language.

At one company where I worked many years ago, everybody referred to me as a Perl guru. The irony was, I also got a personal e-mail at the same time from Rex Swain, the guy who maintained the Perl 5 reference page, asking me to stop leaning on it so much. I was loading the page so frequently that I was individually responsible for some huge percentage of his monthly bandwidth bill. Of course I saved a local copy to my desktop - and of course Rex today has Google ads on the page - but the lesson is that people were calling me a guru, and yet I went to reference material so frequently that I single-handedly constituted a bandwidth issue for the reference maintainer.

I wasn't really a guru, but I was good enough at Perl to believe it when people said it about me, and obviously good enough that they had a reason to say it in the first place. (It also helped that I was young and hadn't yet encountered any real gurus.)

But it isn't necessarily a paradox. It demonstrates the foolishness of job interviews which test on language syntax; I made all my business users very happy, much happier than they'd expected to be, and never even bothered to remember many core elements of the language. I checked the reference page twenty times a day for the same tidbit because it was never worth memorizing - or even remembering at all.

I made my business users happier than they'd expected to be because I redefined the problem I was working on, and the way you do that is you choose the right issues to think about. Language syntax is not a useful issue to think about. Except for language designers, anybody who puts a lot of energy into remembering language syntax is an idiot. That's what Google is for.

The valuable thing to learn when you learn a programming language is the set of core principles behind it. It's much more valuable to be able to discern idiomatic Ruby vs. Ruby that looks like PHP than it is to know a given method name off the top of your head, for exactly the same reason that programmer discipline is more valuable than a version control repository. The productivity boosts associated with using excellent languages come from the good programming habits which good languages encourage, and they have nothing to do with rote memorization. One-liners are useful in this context because a good one-liner compresses syntax down to idiom, and favors idiom over syntax.

Think about it another way: would you learn more about Perl by memorizing its keywords, or playing Perl golf? Memorizing keywords in a programming language is like memorizing vocabulary in a spoken language; it's only useful if the language uses exactly the same grammatical structures as a language you already speak fluently. But the act of compressing code into a one-liner is like the act of creating slang, and if you understand how slang comes into being, you understand how to make new words.

1 comment:

  1. ... which is exactly why it's nice to have IDEs that remember the useless knowledge for you.

    I'm spending much more time on Google in Ruby than I ever did in Java simply because my Java IDE could answer many of the simplest questions for me. "What's that method? What does it return? What was the name of that method I used yesterday?"


Note: Only a member of this blog may post a comment.