

Clingy Lexicals: Closures in perl  - f00li5h
http://f00li5h.pin21.com/blog/Clingy-Lexicals:-Closures-in-perl.html

======
jrockway
There are two topics I refuse to blog about -- monads and how to indent Perl
code. But HN doesn't count as a blog, so here is _jrockway's simple perl style
guide_.

There is one rule: everything is a block. If you write a function, you write
it like:

    
    
        sub foo {
            my $code = 'goes here';
        }
    

Now do this for everything:

    
    
        my %hash = (
            foo => 'bar',
            bar => 'baz',
        );
    
        my $coderef = sub {
            my $hey_just_like_a_normal_sub;
            return sub {
                "OH HAI"
            };
        };
    

If you can condense something onto one line, then do it:

    
    
        my @foos = grep { /foo/ } @stuff;
    
        my $coderef = sub { 42 };
    

This is the most widely-used style, and it's something everyone should do to
be consistent with everyone else. The only time I have ever seen anything else
is in this blog post.

(Okay, cperl-mode does it wrong by default. I changed it a few years ago and
got immediate hate mail. I'm pretty sure there is some script out there that
checks out cperl-mode from git, indents some code with it, and sends email if
the indentation is not exactly the same as it was in 1993. The script also
adds random words from /usr/share/dict/words, and that wordlist only contains
various spellings of "fuck". Apparently.)

~~~
variety
The (attempted) use of indenting and whitespace as a form of expressiveness is
so passé. As demonstrated by the transcendent rise of Python. It's the wave of
the future. Get used to it, man.

