in reply to Re^7: Thread on Joel on software forum : "I hate Perl programmers."
in thread Thread on Joel on software forum : "I hate Perl programmers."

When I see a Swartzian Transform, I think, "Ah! he's sorting the data".
Yeah, but it might take a few brainbeats to notice you're looking at an ST. The sort is bookended between two maps, but not any map/sort/map pipeline is an ST.

If I see:

@a = sort {COMPLEX EXPRESSION <=> COMPLEX EXPRESSION} @b
it's immediately clear data is sorted. Regardless of how complex the expression is,
@a = map {$_->[0]} sort {$a->[1] <=> $b->[1]} map {[$_, COMPLEX EX +PRESSION]} @b
takes more time to register that data is sorted, and just sorted.

ST's feature is speed. Not readability.

Replies are listed 'Best First'.
Re^9: Thread on Joel on software forum : "I hate Perl programmers."
by BrowserUk (Patriarch) on Jun 17, 2005 at 13:04 UTC

    Which is why I format the ST thus:

    @a = map { $_->[0] } sort { $a->[1] <=> $b->[1] || $a->[ 2 ] cmp $b->[ 2 ] } map { [ $_, COMPLEX EXPRESSION ] } @b;

    It makes the map / sort / map structure immediately apparent and allows for arbitrary complexity within the blocks, including multiple lines and even local variable declarations to be used without getting into that whole obfu-style thing.

    A similar layout lends itself to the GRT:

    @a = map{ substr $_, 16 } sort map { m[...(\d+)...( \d+.\d+)...([a-z]4)...] or die "Illformed data '$_' +"; pack 'A4dNA*', $3, $2, $1, $_ } @b;

    I never format single line if or else blocks one line either for same reason that doing so obscures the structure of the code.

    I also like the consistancy with map/grep/sort chains and normal assignment. That is: result = manipulation of inputs

    P6 has the pipe operators which allow you to reverse the flow src ==> tmp => dst, but I don't forsee me using that. I guess I grew up with assemblers, and even cpm/pip where dst = src was the way of things.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.