Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Really Long if/elsif/else blocks

by educated_foo (Vicar)
on May 31, 2008 at 03:04 UTC ( #689381=note: print w/replies, xml ) Need Help??


in reply to Really Long if/elsif/else blocks

A less repulsive bracketing style would help, i.e. one with a bit more space to it. Instead of
if($foo){ $blah} elsif($bar){ $baz}
something a bit more normal like
if ($foo) { $blah } elsif ($bar) { $baz }
or
if ($foo) { $blah } elsif ($bar) { $baz }
makes it easier to see where blocks begin and end. Also, you should use an editor that lets you move between matching delimiters, e.g. "%" in vi or "C-M-f" and "C-M-b" in Emacs.

Replies are listed 'Best First'.
Re^2: Really Long if/elsif/else blocks
by mandarin (Hermit) on May 31, 2008 at 20:29 UTC
    Perl Best Practices by Damian Conway (O'Reilly, 2005) clearly states: "Don't cuddle an else". The recommended way is
    if ( $foo ) { $blah; } elsif ( $bar ) { $baz; } else { $boom; }

      While PBP contains many good recommendations, that is what they are. They are not law, requirements, or to be followed blindly.

      --MidLifeXis

      So what? There are many styles that allow one to easily line up sequences of if/elsif/.../else. "Person X does this, therefore X is the only way" is poor reasoning.
      one of the most petty things included in said book, that he gets the most heat for (its like spaces v. tabs )

      Nope, there is only One True Way ...

      if ( ... ) { ... } else { ... }

      ;>} ... but really <what others have already stated>.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://689381]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2018-07-21 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (449 votes). Check out past polls.

    Notices?