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

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 romping around the Monastery: (5)
As of 2018-03-20 06:56 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (248 votes). Check out past polls.