Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: ?: = Obfuscation?

by Melly (Hermit)
on Dec 01, 2006 at 19:21 UTC ( #587271=note: print w/replies, xml ) Need Help??

in reply to Re: ?: = Obfuscation?
in thread ?: = Obfuscation?

Interesting - and the Perl 6 changes make sense (although they lengthen the golf-courses for everyone ;).

I noticed the point about the implicit parens between ? and : when I was writing a related tutorial, but just sort of shrugged it off - it seemed reasonable (since '?' implies a closing ':'), but in some ways confusing (since you are more likely to be confused by the behaviour of $x?$y=1:$y=0).

I intend to revise and improve the tutorial to try and reflect some of the views expressed in this thread, but without swamping the users for whom the tutorial is written with too many distractions.

BTW do you think, with acknowledgements, it's ok to use code from this thread in the tutorial, or is it polite to ask the individual contributors first?

map{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
Tom Melly,

Replies are listed 'Best First'.
Re^3: ?: = Obfuscation?
by throop (Chaplain) on Dec 01, 2006 at 22:10 UTC
    I like ?: when the args are short.

    I spent years as a LISP programmer. A programmer who has memorized the precedence table will write code that's understandable by others who have memorized the precedence table. Use parenthesis liberally.

    $longways = $widthIsLonger ? $width || 1 : $height || 1;
    may work and is terse, but
    $longways = $widthIsLonger ? ($width || 1) : ($height || 1);
    reads better to me.

    It's mostly the case that if I'm using an operator within the scope of ?: I'll parenthesize.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2017-04-23 09:44 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (430 votes). Check out past polls.