!= is it the same is <> what is better to use?

  • != is it the same is <> what is better to use?

    Thank you

  • They are the same.

    Better is a matter of opinion on this one. It doesn't really matter which you use, but be consistent with whichever you choose.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Thank you

  • I'm with GSquared on this one, personally I like !=, it feels more explicit as opposed to <> which feels less so, but is common in many other languages. Basically chose one and stay with it.

    CEWII

  • != seems easier to read to me, but I'm not sure it matters.

  • In My Point != Is the Best Compared To <>

  • Guess it depends

    Mostly on the programming background you have

    In C languages it would be !=

    Whereas in Visual Basic languages it would be <>

    I myself , i mostly write in Visual Basic or VbScript and therefore will always use <>

    wkr,

    Eddy

  • != and <> are same, it just depends on your coding style, whatever you like :cool:.


    Sujeet Singh

  • If there's nothing to choose between two different syntaxes, I usually go for the ANSI standard. That's why I prefer <> in this case.

    John

  • You will probably find that <> is just a little bit easier for others to understand since it is more common.

    Todd Fifield

  • After running some tests in python, I don't think the two operators are the same. This is definately not conclusive proof but does show a difference in execution speed.

    >>> import timeit

    >>> winner = []

    >>> t1 = timeit.Timer(stmt = "1 <> 2")

    >>> t2 = timeit.Timer(stmt = "1 != 2")

    >>> def t():

    ... t1time = t1.timeit()

    ... t2time = t2.timeit()

    ... if t1time < t2time:

    ... winner.append(1)

    ... elif t2time < t1time:

    ... winner.append(2)

    ...

    >>> for i in range(5):

    ... for i in range(100):

    ... t()

    ... print "<>:\t%s!=:\t%s" % (winner.count(1), winner.count(2))

    ... winner = []

    The above code runs 100 speed comparisons ("1 <> 2" vs "1 != 2") and counts the winners. This is then executed 5 times, giving a total of 500 comparisons.

    The output when I ran this

    <>: 45

    !=: 55

    <>: 41

    !=: 59

    <>: 41

    !=: 59

    <>: 46

    !=: 54

    <>: 50

    !=: 50

    The majority of the runs show that != is slightly quicker than <>. This is probably because != just evaluates wether a single comparison is true or false, wheras <> may need to do both a more than comparison and a less than comparison before concluding True or False.

    Plus <> is not documented in most languages, even in this fairly comprehensive C and C++ operators list - http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B

    Bodsda

  • in sql 2005 both gave results at same time or some times != is better but i dont know for what reason.

    Regards
    Durai Nagarajan

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply