[advanced search]
Results from the most recent live auction are here.
21 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 12-28-2003, 08:15 PM   · #1
deadserious
Senior Member
 
Trader Rating: (13)
Join Date: Aug 2002
Posts: 1,300
NP$: 2.85 (Donate)
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
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)


Please register or log-in into NamePros to hide ads
deadserious is offline   Reply With Quote
Old 12-28-2003, 09:00 PM   · #2
DuffMan
NamePros Lottery Guy™
 
DuffMan's Avatar
 
Name: Eric
Location: Maryland, USA
Trader Rating: (16)
Join Date: Jul 2003
Posts: 603
NP$: 77.00 (Donate)
DuffMan has a spectacular aura aboutDuffMan has a spectacular aura about
I normally use if ($day == 'Monday'). The other way around just doesn't seem right to me.
__________________
Eric AKA DuffMan
[HG Interactive]
[ ShoutPro]
DuffMan is offline   Reply With Quote
Old 12-28-2003, 11:46 PM   · #3
Jeanco
RyanPrice.ca - Developer
 
Name: Ryan Price
Trader Rating: (28)
Join Date: Dec 2003
Posts: 1,331
NP$: 34.00 (Donate)
Jeanco is a jewel in the roughJeanco is a jewel in the roughJeanco is a jewel in the rough
always variable first in comparison operations.
__________________
Ryan Price - Webmaster
www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign
Jeanco is offline   Reply With Quote
Old 12-29-2003, 01:18 AM   · #4
Kodeking
DomainsForCharity™ Person
 
Kodeking's Avatar
 
Name: Jason
Location: Naperville Illinois
Trader Rating: (29)
Join Date: Jun 2003
Posts: 1,803
NP$: 493.50 (Donate)
Kodeking is just really niceKodeking is just really niceKodeking is just really niceKodeking is just really nice
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.

Kodeking is offline   Reply With Quote
Old 12-29-2003, 10:52 PM   · #5
zoya19
NamePros Member
 
Name: Kathy
Location: Ontario
Trader Rating: (10)
Join Date: Oct 2003
Posts: 112
NP$: 0.00 (Donate)
zoya19 will become famous soon enoughzoya19 will become famous soon enough
We have always used: ($day == 'Monday'), as well.
zoya19 is offline   Reply With Quote
Old 12-29-2003, 10:59 PM   · #6
CreativeLogic
NamePros Regular
 
CreativeLogic's Avatar
 
Name: Ryan Amos
Trader Rating: (15)
Join Date: Sep 2003
Posts: 893
NP$: 18.00 (Donate)
CreativeLogic has a spectacular aura aboutCreativeLogic has a spectacular aura about
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.
__________________
Online Time Tracking
CreativeLogic is offline   Reply With Quote
Old 12-29-2003, 11:10 PM   · #7
-RJ-
Mr. Mayor
 
-RJ-'s Avatar
 
Name: Ron James
Location: Bay Area, CA
Trader Rating: (221)
Join Date: Feb 2003
Posts: 12,681
NP$: 17646.98 (Donate)
-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute
Autism Find Marrow Donors! Save The Children Cystic Fibrosis Ethan Allen Fund Myanmar Relief
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)
__________________
Twitter http://twitter.com/domainbuyer
-RJ- is offline  
  Reply With Quote
Old 12-29-2003, 11:30 PM   · #8
deadserious
Senior Member
 
Trader Rating: (13)
Join Date: Aug 2002
Posts: 1,300
NP$: 2.85 (Donate)
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
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.
deadserious is offline   Reply With Quote
Old 12-30-2003, 12:53 AM   · #9
Alpha
NamePros Regular
 
Name: Todd
Location: California
Trader Rating: (0)
Join Date: Jun 2003
Posts: 249
NP$: 401.00 (Donate)
Alpha is an unknown quantity at this point
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
Alpha is offline   Reply With Quote
Old 01-11-2004, 12:15 AM   · #10
Japsta
New Member
 
Name: Japsta Jack
Location: Australia
Trader Rating: (0)
Join Date: Jan 2004
Posts: 6
NP$: 10.00 (Donate)
Japsta is an unknown quantity at this point
yea fully
__________________
Japsta
Japsta is offline   Reply With Quote
Old 01-14-2004, 02:30 AM   · #11
linuxfan
NamePros Member
 
Trader Rating: (0)
Join Date: Dec 2003
Posts: 67
NP$: 95.00 (Donate)
linuxfan is an unknown quantity at this point
yes. all php code i have done is variable first.. putting it opposite makes my life pretty hard. very difficult to read... bleh.
linuxfan is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
EscrowDNS Website Header Design EscrowDNS
Advertise your business at NamePros
All times are GMT -7. The time now is 10:10 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0