The recent discussion at Some thoughts around the "is Perl code maintainable" discussion got me to thinking about the PM obfuscated code section. One of the posts talked about the Perl culture's love for obfuscation. My first reaction was a) not me, I don't like obfu or golf and rarely read posts containing them and b) the fact that some people like obfu and golf doesn't mean that the Perl community as a whole thinks they are good ideas in production code. My guess is that even people who enjoy obfu rarely use it in their day jobs. So then I began to wonder, if that's true, would it be worth stating so explicitly here at PM? I'm thinking of an extra sentece or two in the description at the top of the obfu section along the lines of:

Obfuscation and golf can be fun and can help hone skills useful in writing real code, but they are not meant to be, in themselves, good examples of Perl code. Post and read here to impress and be impressed with minutia, but put your production oriented code in the Code Catacombs or Meditations sections. In other words kids, do try this at home, just don't try it at work! :-)

That's probably a little heavy-handed but can maybe get some discussion going about what we'd like it to say.

update : corrected link to Code Catacombs, added formatting

  • Comment on Better labeling of obfuscated code section

Replies are listed 'Best First'.
Re: Better labeling of obfuscated code section
by eyepopslikeamosquito (Archbishop) on Aug 12, 2007 at 01:52 UTC

    Yes I strongly agree with this (despite my dubious past).

    I remember when writing The Lighter Side of Perl Culture (Part III): Obfu how determined I was to create the right impression. Accordingly, before launching into the fun, recreational pastime of obfu, I started on a cautionary note, emphasizing that:

    1. Perl is indeed a fine language for writing maintainable systems.
    2. Obfuscation has no place in production code.
    3. Obfuscation started long before Perl did. This was clearly demonstrated in the History section, which notes that the Obfuscated C competitions started long before Perl did. (Though it was perhaps unfortunate that Tim (Toady) happened to triumph in one of these early IOC contests ;-).

Re: Better labeling of obfuscated code section
by f00li5h (Chaplain) on Aug 12, 2007 at 08:06 UTC

    q{ Obviously perl golf is a game, in stark contrast to Best Practices. }

    This is the disclaimer that I attach whenever I show off golfs... it does appear on my scratchpad (although It should be part of my sig too, I guess)

    I'm 100% sure that those who write golfs don't use them in production. The only ones in question are those who look at an obfu and want to write their own and haven't encountered one in the wild yet... Perl programmers are smart enough to know that someone's going to have to read it...

    The langauge is both a toy and a tool, people will saw their own arms off if they start playing with chainsaws, the same thing applies to obfus.

    TheDamina opens PBP with q{ Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live }

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

      I'm 100% sure that those who write golfs don't use them in production.
      The same can't be said for those who don't write golfs...

      11 years ago, shortly after starting to use Perl, my client demanded that I implement "encryption". I had no idea how encryption worked, or how to implement it in Perl. CPAN was young, and not nearly as rich as it is today.

      So I searched Google, and found this: RSA in 3 lines:

      #!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj $/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1 lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)

      This was used by my client for years to encrypt and transport customer data from a website via FTP.

      It worked, but I wouldn't recommend the practice :)

      Clint

        Yes, the same is true of golfs as of obfus... they can get you in trouble in a production environment.

        I'm surprised you didn't wake up one night with an axe in your spine, and an angry man in a black tshirt standing over you ranting about revenge...

        You were lucky this time ;)

        @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

Re: Better labeling of obfuscated code section
by dynamo (Chaplain) on Aug 14, 2007 at 15:58 UTC
    I agree that obfu's suck, at least outside of PerlMonger meetings and job interviews where they ask you to explain what they do (this can actually be pretty fun.)

    But golfs are useful at times and shouldn't be lumped in. It's a very different process trying to make code unreadable to humans (obfus) than the process of trying to optimize for code size (golfs).

    A golf is a refining process toward simplicity. A obfu is a refining process in the other direction.

    Gentlemen prefer golfs.

      I agree that code that wins at golf is not necessarily obfuscated. But the game of golf has a goal contrary to best practices - to make the code shorter regardless of its impact on clarity. Best practice would be something like this: (short clear code)++ ... (short unclear code)--. Golf is like this: (short code)++.