Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Code blocks with ternary operator or trailing conditionals

by sundialsvc4 (Abbot)
on Feb 09, 2014 at 15:10 UTC ( #1074125=note: print w/replies, xml ) Need Help??

in reply to Code blocks with ternary operator or trailing conditionals

I’ll agree rather strongly with kcott and the others on this one:   when the language fairly-obliges you to use a few “extra” keywords, do so.   Why?   Maybe because these “extra few” symbols serve to bypass ambiguities in the underlying grammar, such that there now becomes, and in the general(!) case, only one way that your intentions might be evaluated by the parser and so on.   Every language has characteristics like this, somewhere in the any every language.   There will be a “right way” that might superficially seem odd or inconvenient.   Why did they require that extra stuff?   Maybe just because it made the grammar necessarily-stronger in a place where it truly needed to be stronger.

Also, think carefully about long-life maintainability of the code ... because computer software does have a very long life-span during which it will pass through many hands besides your own.   It could well be that a future change to your code, if written in this way, could have unintended consequences that do not result in a syntax-error.   (And this whether you were the one making the change, or not.)     “Two paths diverged in a snowy wood,” and both were equally valid, and [Perl...] took the other one and raised no yellow flags.   Maybe they affect the direct code-line that you are modifying at that time, but maybe they do not ... and does your project really have an all-encompassing test suite that is constantly maintained along with the code?   Didn’t think so.   So, this is just something that you should avoid as a matter of course, because hair-follicles are a precious thing . . .

  • Comment on Re: Code blocks with ternary operator or trailing conditionals

Replies are listed 'Best First'.
Re^2: Code blocks with ternary operator or trailing conditionals
by puterboy (Scribe) on Feb 09, 2014 at 15:26 UTC
    Thanks for the good lesson. I don't disagree with you (or the others who have answered similarlY) at all.

    My reason for asking was not out of coding "laziness" but rather to seek new grammatically *valid* tricks.

    The cool thing about Perl is that I find more often than not that there are cleaner/better ways of doing things than are available in other C-like languages. Hence, my reason for asking - to learn. Thanks!!!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-01-20 21:15 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.