Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

by Tux (Monsignor)
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

Comment on Re^2: Two simple code style advice questions (tye)
Select or Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-11-29 14:16 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (751 votes), past polls