Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

xsawyerx (8978)

xsawyerx
  (email not shown publicly)

Journal of xsawyerx (8978)

Wednesday June 24, 2009
02:44 AM

Another stupid geek argument

[ #39166 ]

While I contemplate on this new pale white design of use.perl.org, hoping it's either temporary or half of what it's meant to be, I wanted to share an argument I had yesterday at $work.

A co-worker presented me a problem:

34 sub scan_array {
35     my ( $item, $arrayref ) = @_;
36
37     # does the $item and $_ equal
38     if ( any { lc($item) eq lc($_) } @{$arrayref} )   ||
39     # or does $item is part of $_ but not equal to it
40        ( any { $_ =~ /$item/i } @{$arrayref} )           {
41         return 1;
42     }
43     elsif  {
44       return 1;
45     }
46
47     return 0;
48 }
syntax error at tests_include.pl line 38, near ")   ||"
Global symbol "$arrayref" requires explicit package name at tests_include.pl line 40.
syntax error at tests_include.pl line 40, near "} )

"why can't it find the arrayref ?!"

Can you spot the error? I have. The if() is missing the encompassing brackets. What actually happened is that perl is thinking that the if() statement ended with the first closing bracket, and then could not interpret the || after. Instead of running if (CONDITION || CONDITION), it ran IF (CONDITION) || CONDITION and according to the syntax of Perl, this shouldn't work, and it didn't.

After explaining to my co-worker (who is indeed a talented programmer) the simple error, he claimed that Perl is stupid because this is the way it works. Now, I should note that I don't really care when people rag on Perl since they're plainly missing something very awesome. I merely explain and move on, albeit often I ignore when I sense a large concentration of ignorance or "showoffness". However, this annoyed me. Since I have a deep interest in optimal writing, programming patterns and coherent coding styles, I found this particularly annoying, as it is simply a matter of incorrect syntax usage, clearly not a language problem.

I stated simply that in almost every language, you have brackets around the if(), and when he proclaimed that in Pascal (of all languages, Pascal? Really?) it is not like that, I simply reaffirmed that Pascal decided not to have that, good for Pascal. However, Pascal just uses the next then to understand when the if ends. That's all. Perl decided to be more pro-active about this and allow more readable code (readable? Perl? YES!). That's also why Perl has mandatory code brackets even on a single if(). Perl however, does allow you to remove both the code brackets and if condition brackets on postfix if()s.

This argument (as many other stupid geek arguments) ensued and enrolled two other developers who both suggested that what I say makes the most sense but that even if you could write it without the condition brackets, it wouldn't be as understandable, and that's an additional minus on its own.

If you want to complain about a language, try to pick better things to complain about. I could give you half a dozen things I don't like about Perl (I think...) which are waaaaay better to complain about besides the fact that "it makes me write an additional pair of brackets around the if, what the fuck?!" <-- exact quote OMG.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • It is stupid that Perl demands that outer parentheses if other languages, including Perl 6, do just fine without. You are rationalising that "clearly language problem" if you say more punctuation makes it more readable.

    Obligatory CPAN: looks like that subroutine can be replaced with Tie::CPHash.

    • The point is not that "Perl cannot do it", at least to me. The point is that if you want to pick a reason why "Perl sucks"(tm), there are far better reasons to exclaim that than the fact that it chose to have explicit parenthesis on if conditions.

      This is the same tone of things as "Perl sucks because if I have only one statement for an if block, I have to still put code blocks, and then I have a line with just one curly bracket!!!"[1] Excuse the exclamation marks (trying to make it seem realistic, did it wo