Gossamer Forum
Quote Reply
Logic
Hm. Out of interest; how would you of wrote the following block:

Code:
unless ($query->param) { &print_poll; } # print poll
else { &print_results; } # print results

Would you of gone for the if, elsif, else option, or maybe shorthand ? : etc?

- wil

Last edited by:

Wil: May 8, 2002, 8:12 AM
Quote Reply
Re: [Wil] Logic In reply to
Not sure. Personally I would use 'if' then 'else'. Not sure if there are any speed differences though Tongue

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy.] Logic In reply to
Not worried about speed differences (I highly doubt that there is a speed difference, anyway) just wondering more about the way people think :-)

- wil
Quote Reply
Re: [Wil] Logic In reply to
I try to only use unless if there is one clause (i.e. trying to unravel things like unless (a and !b) makes my head hurt), and no else. I would have gone:

if ($query->param) { &print_results; }
else { &print_poll; }

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Logic In reply to
I like to be different:

$query->param ? &print_results : &print_poll;

Edit: (and hate braces) {}

Last edited by:

Paul: May 8, 2002, 12:33 PM
Quote Reply
Re: [Alex] Logic In reply to
Alex

That is the way I originally did mine, but for some bizarre reason went and played with unless - I haven't used unless in a while so I threw one in.

On the other hand; for some reason I don't tend to use if, elsif, else unless I actually have three or more conditionals so I can throw in the whole if, elsif, else in. If I leave one of these three out I get paranoid that my program will break - bad experience with leaving an else out in my earlier days :-)

- wil
Quote Reply
Re: [Paul] Logic In reply to
Paul

I just knew you'd use ? and :! :-) You're a big fan of those in your code I've noticed!

- wil
Quote Reply
Re: [Wil] Logic In reply to
I find it nicer and quicker than all the if's/elses......you can make big long if/elsif/else but without all the crap.

Code:
defined $something ?
do_something() :
defined $this ?
do_this() :
defined $last ?
do_last() :
end();

Which is the same as.....

Code:
if (defined $something) {
do_something()
}
elsif (defined $this) {
do_this()
}
elsif (defined $last) {
do_last()
}
else {
end()
}
Quote Reply
Re: [Paul] Logic In reply to
Not to mention Paul's method decreases file size and executes a tiny bit faster. I like that method as well Blush
Cheers,
Michael Bray