Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Hidden Benefit of Perl Syntax

by Errto (Vicar)
on Jan 07, 2008 at 23:43 UTC ( #660976=perlmeditation: print w/replies, xml ) Need Help??

I was never a big fan of the if..elsif construction in Perl with the mandatory BLOCK. I always preferred the C-style approach in which the dependent statement was just a statement, which could be a compound statement or not. However, just this afternoon I had some code in a C-style language like:
if (something) unnecessary_statement(); if (other_thing) important_statement();
I then commented out the unnecessary statement. Oops.

Update: I realize Perl is one of many languages that uses this construct. It just happened to seem especially relevant here.

Replies are listed 'Best First'.
Re: Hidden Benefit of Perl Syntax
by TimToady (Parson) on Jan 08, 2008 at 00:06 UTC
    Another hidden benefit is that we noticed in Perl 6 that if we keep the curlies mandatory, we can make the parens optional. And we want to do that, because the curlies represent something real (a closure) while the parens are merely a disambiguating syntax.
Re: Hidden Benefit of Perl Syntax
by FunkyMonk (Canon) on Jan 07, 2008 at 23:50 UTC
    Do more C

    and the problem will go away


    Do more Perl

    and the problem will also go away.

    I know what I'd choose


    although, once upon a time, I'd have chosen more C

Re: Hidden Benefit of Perl Syntax
by Nkuvu (Priest) on Jan 08, 2008 at 00:26 UTC

    More than once I've seen people get tripped up when adding statements to conditional blocks without braces. I've done this myself, not claiming to be perfect or anything. For example, adding lines to code like:

    if (condition) some_statement();

    Resulting in the "obviously wrong if you know what you're looking for but surprisingly easy mistake to make" code:

    if (condition) some_statement(); some_other_statement(); some_random_statement();

    Added: I mean "obviously wrong" when the code change required is to add the "some_other_statement" and "some_random_statement" to the conditional. If you just look at the second code snippet without some other context, it's not clear whether it's just an indentation issue or an error due to lack of braces.

      Obvious wrong is in the eye of the beholder. If you happen to (have to) work with someone who doesn't care about indentation at all, and yank/puts code lines from other places without giving them the correct indentation, you end up with code blocks that look wrong, but are actually exactly what he meant.

      Guess I should be moving to hates-software ...

      Enjoy, Have FUN! H.Merijn

      That is why Python is clearly superior to these other languages.

      - tye        

Re: Hidden Benefit of Perl Syntax
by sundialsvc4 (Abbot) on Jan 08, 2008 at 17:56 UTC

    That's also a hidden benefit of version-control systems. Sometimes when a program starts to barf unexpectedly, and I know that I did something funky at two o'clock in the morning last night (when everyone writes their best code ... c'mon, admit it...), it's very handy to be able to side-by-side compare the two latest revisions.

    A couple of minutes later you find it, slap your forehead “Doh!!” ... and grimace, once again reminding yourself not to do that when you have a six-pack hangover.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://660976]
Approved by FunkyMonk
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2018-02-20 16:10 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (272 votes). Check out past polls.