|
-
Apr 16th, 2007, 11:45 PM
#1
Thread Starter
Addicted Member
[RESOLVED] [2.0] the "correct" if statement syntax...if any
Hello everyone,
I am a little bit confused as the the "correct syntaxt" for an if statement, as i frequently see sites use either...
Sample 1:
Code:
if (someString != "hi") {
//do stuff }
Sample2:
Code:
if (!(someString == "hi")) {
//do stuff }
i see the first one more often...is there a write or wrong, or just preference...
Thanks, Justin
-
Apr 16th, 2007, 11:54 PM
#2
Hyperactive Member
Re: [2.0] the "correct" if statement syntax...if any
I would use the first sample per preference because it's easier to read without second thought. Do the same thing in a different way. You'd have to decide what you would rather read of the two versions. I can see some users missing the ! at first in the second example, but definitely not in the first example.
Cheers!
-
Apr 17th, 2007, 12:10 AM
#3
Re: [2.0] the "correct" if statement syntax...if any
I strongly second gjon's sentiments. I can't see any real justification for the second way as it simply complicates the code without adding value. I'd be fairly sure that the first way is also more efficient.
-
Apr 17th, 2007, 12:14 AM
#4
Re: [2.0] the "correct" if statement syntax...if any
Thirded. You should try to use as few operators as possible in order to maximise readability.
-
Apr 17th, 2007, 12:22 AM
#5
Thread Starter
Addicted Member
Re: [2.0] the "correct" if statement syntax...if any
Hey,
Thanks, Thread Resolved.
just wasnt sure whether there was a purpose if any to the second one...i too use the first 1, again for readability and it seems more logical to me...
Thanks, Justin
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|