http://www.perlmonks.org?node_id=587271


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, pm@tomandlu.co.uk

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.