Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.
Moderator: General Moderators
jaoudestudios
DevNet Resident
Posts: 1483 Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey
Post
by jaoudestudios » Thu Oct 29, 2009 5:10 am
Which method is better?
Code: Select all
if ($x == 1)
{
return true;
}
else
{
return false;
}
or
thanks
Jonah Bron
DevNet Master
Posts: 2764 Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California
Post
by Jonah Bron » Thu Oct 29, 2009 6:43 pm
Um, I think that on the hardware level, "return $x==1" is slightly better, plus there is slightly less interpreting. Though, it's not so good for readability. Maybe "return ($x==1)"?
Why?
jaoudestudios
DevNet Resident
Posts: 1483 Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey
Post
by jaoudestudios » Fri Oct 30, 2009 2:40 am
We're having a debate at work.
I agree with what you said, may be less interpreting but also less readable.
Thanks!
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Oct 30, 2009 2:48 am
jaoudestudios wrote: We're having a debate at work.
I agree with what you said, may be less interpreting but also less readable.
Thanks!
I think that the "if" version is less readable
I'd always use the "single-line-return" version.
There are 10 types of people in this world, those who understand binary and those who don't
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Fri Oct 30, 2009 10:20 am
In your position, I'd have used:
Still one line, and still readable
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.