in reply to Legible or Obfuscated?

Paul Graham once made the point that just having each line be simple isn't everything. There is no doubt that any given line of BASIC is much simplier than almost any given line of LISP. However, on the average, the BASIC program will be much, much longer to solve the same problem. He argues that the complexity of a program is:

effort per line * number of lines

So if we assume that the LISP program has an average line complexity of 10, and the BASIC program is at 1, then it seems to be that BASIC is a simplier language. But if the BASIC program is 100 time longer, than it's really a win for LISP.

He made a rather complelling argument that a paper on some advanced mathmatical topic may be so full of specific mathmatical language that it often takes the uninitiated hours to read a single paragraph. However, without that notation, the paper would be a hundred times longer than it is.

On another point, I tend to write my code so that portions that are likely to change are easy to change. For example, lets assume that you have an AoA that needs to go into an HTML::Template loop. Here is my idiomatic solution:

$tmpl->param( loop => [ map {{ foo => $_->[0], bar => $_->[1], baz => $_->[2], }} @AoA ] );

The part likely to change here is the parameters being sent into the loop. As such, it's easy to change those. But look at the rest of the statement. To fully understand it, you have to realize that the first curly brace creates a block for the map statement, and the second curly creates a hashref. Plus, you need to know how to handle references in general, a concept that many new Perl programmers struggle with for a while (though IMHO, it's a critical step in learning Perl).

Really, it all comes down to how much Perl you know. It is only unreadable if you don't know the construct used.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re: Re: Legible or Obfuscated?
by diotalevi (Canon) on Aug 10, 2004 at 13:08 UTC
    map {{ PAIRS }} ...dwims the direction you said but not why you thought. If the contents of the two braces look like pairs or like statements this is used to decide whether the you just meant to introduce a block (for use with next/last/redo) or a hash. This is why map +{ }, ... is important because it looks more like a hash ref and does not involve dwimmery to decide that it is a hash. map {; ... } ... is the other dwim-free mode for running statements and returning lists (possibly of pairs).