Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "If isSomething=false" or "if not isSomethig"?

    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?
    Code:
    if isNumeric(var)=false then
    ...
    or
    Code:
    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.

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    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

  • #3
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    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...
    Code:
    If (Not IsNumeric(aNum)) Then
    	Response.Write "foo<br>"
    End If
    Last edited by M@rco; 11-27-2003 at 11:18 PM.
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)

  • #6
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    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
    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...

    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #8
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well if raf AND M@rco agree about that........... I can just do the same


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •