Results from the most recent live auction are here .
21 members in the live chat room. Join Chat !
12-28-2003, 08:15 PM
· #1 Senior Member
Join Date: Aug 2002
Posts: 1,300
NP$: 2.85 (
Donate )
PHP: if ($day == 'Monday') or if ('Monday' == $day) Variable first or ?
I've asked this before, but would like to see what everyone thinks about it now.
Is it better to place the variable first or last? Which do you prefer?
placing it first:
if ($day == 'Monday')
placing it last:
if ('Monday' == $day)
12-28-2003, 09:00 PM
· #2 NamePros Lottery Guy™
Name: Eric
Location: Maryland, USA
Join Date: Jul 2003
Posts: 603
NP$: 77.00 (
Donate )
I normally use if ($day == 'Monday'). The other way around just doesn't seem right to me.
12-28-2003, 11:46 PM
· #3 RyanPrice.ca - Developer
Name: Ryan Price
Join Date: Dec 2003
Posts: 1,331
NP$: 34.00 (
Donate )
always variable first in comparison operations.
12-29-2003, 01:18 AM
· #4 DomainsForCharity™ Person
Name: Jason
Location: Naperville Illinois
Join Date: Jun 2003
Posts: 1,803
NP$: 493.50 (
Donate )
Quote: Originally posted by Jeanco always variable first in comparison operations.
Yeah, you want to know if it is an instance of something.
__________________
Quote: Clan-Forums.com >> $30 BoardingForum.com >> $100 TalkWebHosting.com >> $200 AvoidChapter13.com >> $100 Send PM to make lesser offers on the above names.
12-29-2003, 10:52 PM
· #5 NamePros Member
Name: Kathy
Location: Ontario
Join Date: Oct 2003
We have always used: ($day == 'Monday'), as well.
12-29-2003, 10:59 PM
· #6 NamePros Regular
Name: Ryan Amos
Join Date: Sep 2003
Posts: 893
NP$: 18.00 (
Donate )
Honestly it doesnt matter. Either way you are going to get the true or false result. So it doesn't matter which but it has become a standard in almost all languages to do variable then comparison then what you are comparing.
12-29-2003, 11:10 PM
· #7 Mr. Mayor
Name: Ron James
Location: Bay Area, CA
Join Date: Feb 2003
Posts: 12,681
NP$: 17646.98 (
Donate )
It's interesting. I've been around awhile and never seen a programmer put the variable second in comparisons. It would work either way, I'm just wonding where you picked up that style of coding and what the logic behind it was?
if ('Monday' == $day)
12-29-2003, 11:30 PM
· #8 Senior Member
Join Date: Aug 2002
Posts: 1,300
NP$: 2.85 (
Donate )
Someone suggested that it was a better way to do it to for error checking reasons is where I picked it up.
So if you accidentaly make the mistake of using one = sign where you should be using two in a comparison it will give you an error and point you right to the line of code with the problem rather than replacing the value of the variable. But I still use variable first because it's just natural to me.
12-30-2003, 12:53 AM
· #9 NamePros Regular
Name: Todd
Location: California
Join Date: Jun 2003
Posts: 249
NP$: 401.00 (
Donate )
Well the way I learned was placing variables first. It also makes it MUCH easier to an editor to read your code that way.
BTW: Deadserious please clear your PM inbox. I have been trying to PM you but it won't let me.
__________________
--Alpha
01-11-2004, 12:15 AM
· #10 New Member
Name: Japsta Jack
Location: Australia
Join Date: Jan 2004
yea fully
__________________
Japsta
01-14-2004, 02:30 AM
· #11 NamePros Member
yes. all php code i have done is variable first.. putting it opposite makes my life pretty hard. very difficult to read... bleh.
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off