Hi Cyril, I'm CCing the list - I hope it's OK (see the last line of my signature for more information).
On Wed, 4 Apr 2012 12:22:41 -0400 Cyril Deba <cyril.d...@gmail.com> wrote: > Hi Shlomi, > > I did read your statement about using ternary statements. So, just to > confirm. You think that the following is a bad code, don't you? Or I just > did not understand your statement correctly? > > *my $expected = 10; > * > *my $candidate = 5; > * > * > * > *my $result = ($expected == $candidate) ? foo() : bar(); > > * > * > * > *print $result; > * > * > * > *sub foo { > * > * return "I am a string"; > * > *} > * > * > * > *sub bar { > * > * return "I am a super string"; > * > *}* Well, your mailer has mangled the non-HTML version of this code, but luckily I can still read it. I don't think this is bad code because both clauses of the ternary operators lack side-effects. People may call to functions or methods within the clauses of the ternary operator (or use other non-stateful operators) and that's perfectly OK, as long as they are not too complex (in which case, one should use if/else with return). Note that one can also do something like: return COND() ? $self->if_method( ARGS ) : $self->else_method( ARGS ); Where both if_method and else_method may change the object's state and it also seems OK. Maybe I should clarify my intentions on the page. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ The Case for File Swapping - http://shlom.in/file-swap An apple a day keeps the doctor away. Two apples a day will keep two doctors away. — one of Shlomi Fish’s relatives Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/