...

View Full Version : "If isSomething=false" or "if not isSomethig"?



jeskel
11-26-2003, 10:26 AM
Hi,
I guess the tilte of my thread is kind of self explanatory... I'm just wondering what is the best thing to do when you want to know if a var is not "something" (same for positive)
'm a bit picky bu what's the best?


if isNumeric(var)=false then
...

or


if not isNumeric(var) then
...

My guess is that if there are two different ways of doing the same thing it's probably because t might be used in different situations... But i cant figure out the difference here.

Oakendin
11-26-2003, 03:58 PM
Doesn't seem to be a difference to me. Does the exact same thing for me in both cases. There's probably a text book answer out there, but I don't have any VBScript references handy.



Dim aNum
aNum = 2
'aNum = "foobar"

If isNumeric(aNum)=false then
Response.write "foobar<br>"
End If

If NOT isNumeric(aNum) then
Response.write "foo<br>"
End If

jeskel
11-26-2003, 04:44 PM
I usually use if not... tested with "equal false", did the same thing as expected... But even if it's only in theory, I guess there must a difference somewhere... Can't find it. Well, as long as I'm sure that using "if not" isn't a bad thing, I'm alright :)

M@rco
11-27-2003, 11:16 PM
Personally I prefer the Not operator because it's shorter and more readable IMHO, but neither is "better" than the other in any measurable sense.

In addition, I tend to add extra C/C++/JavaScript style brackets around the expression for added clarity...
If (Not IsNumeric(aNum)) Then
Response.Write "foo<br>"
End If

raf
11-27-2003, 11:44 PM
Sidenote : i personally prefere a more defensive approach --> so 'positive' matching. So i would check if it is numeric and move the ... to the else clause. (But that's more a general cding-attitude : code as defensive as possible and if possible, check against a 'concrete' value or value-patern

Also : isnumeric has it's flaws. If you run a search here you'll find a few posts about it, so you better use a regular expressions and then run the code if it returns false. (Whammys regex page contains some usefull ones)

jeskel
11-28-2003, 12:54 PM
Originally posted by raf

Also : isnumeric has it's flaws. If you run a search here you'll find a few posts about it, so you better use a regular expressions and then run the code if it returns false. (Whammys regex page contains some usefull ones)
don't worry, that was just an example... :) I was part of that thread where the 2e3 issue was discussed ;)

thank you guys for all enlightning comments and sharing your coding habits with me :thumbsup:

M@rco
11-29-2003, 06:07 AM
Originally posted by raf
Sidenote : i personally prefere a more defensive approach --> so 'positive' matching. So i would check if it is numeric and move the ... to the else clause. (But that's more a general cding-attitude : code as defensive as possible and if possible, check against a 'concrete' value or value-patern:thumbsup: Gets my vote. Always test on what you're expecting and handle exceptions appropriately. I was just going along with the example that was presented...

;)

jeskel
11-29-2003, 01:48 PM
well if raf AND M@rco agree about that........... I can just do the same :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum