Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^2: Two simple code style advice questions (tye)

by Tux (Abbot)
on Jan 18, 2013 at 16:17 UTC ( #1014080=note: print w/replies, xml ) Need Help??

in reply to Re: Two simple code style advice questions (tye)
in thread Two simple code style advice questions

But I've come to find ternaries to often be less quick/easy to read than something like:

I am with BrowserUK here, and I am happy to see you are using the "I find" instead of the way to often used "it is better to" (here in the monastery), as many idioms that are easy to parse by person A causes headaches to person B.

Personally I would try to avoid statement modifiers to any cost. I hate them. They make me read code exactly opposite of what the author meant.

I have no trouble reading (nested) ternary operations. Maybe too used to those from doing C.

You also doing java? Where 42 == $n is quite often preferred over $n == 42 because of "string".equals ($n) implies NULL checks.

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^3: Two simple code style advice questions (short)
by tye (Sage) on Jan 18, 2013 at 17:44 UTC
    You also doing java?

    Nope. I started trying out "42 == n" in C a long time ago to avoid accidentally writing "if( n = 42 )".

    In this case, I wrote "42 == $n" as I find "42" to be the much more interesting part of the expression. I prefer to put shorter things and more interesting things first to speed parsing.

    - tye        

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014080]
and a log crumbles through the grate...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-06-18 00:32 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (107 votes). Check out past polls.