http://www.perlmonks.org?node_id=129936


in reply to (jcwren) Re: My code and your stupidity don't mix!
in thread Would you use 'goto' here?

I have, in no way, said that obfuscated code is a good idea. I have also not said that using undocumented features of Perl is a good thing to do. I'm talking about lesser-known features, like goto &foo, that are documented and correct to use in certain situations.

Here's an example - would you say that using the Schwartzian Transform or Orcish Manauver is "obtuse"? Yet, one uses map liberally and the other uses ||=, which is a lesser-known feature. (It receives less than one page in the 3rd ed. Camel book.) If I were to take the Orcish Manauver to a code review in most Perl shops, 2/5 would definitely vote it's obfuscated! Yet, I hope you're not advocating that the Orcish Manauver is unmaintainable.

Yes, you have a number of years more in the industry. However, nearly all my years have been rewriting badly written code and being forced to make it more maintainable in order to do anything with it. My "coolness" may cost the company three days, but someone else's "stupidity" just cost the company my last month's of work.

I'd much rather someone use lesser-known features, but wrote good code, than someone use the easier 50% and write it badly.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Orcish Maneuver
by AidanLee (Chaplain) on Dec 06, 2001 at 22:42 UTC
    What, if you would enlighten me, is an Orcish Maneuver? There are only mentions of it by name on the site, but no examples...

      The Orcish Maneuver is a term coined by Joseph Hall in his book "Effective Perl Programming" (co-authored by merlyn). Here's the essence of it:

      my @sorted = sort { ( $times{$a} ||= -M $a ) <=> ( $times{$b} ||= -M $b ) } @old_array;

      The "orcish" (a bad attempt at humor: "or cache") maneuver basically caches the results of an expensive lookup using the ||= operator. This operator says, in the above code, that $times{$a} will be evaluated or, if it is false, set it to the value of -M $a. (-M is the file test operator for last modified time). This allows you to cache the results of -M rather than call it every time. This has the same effect as:

      for ( @old_array ) { $times{ $_ } = -M $_; } my @sorted = sort { $times{$a} <=> $times{$b} } @old_array;

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      My point exactly.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.