November 17, 2011 at 1:56 pm
!= is it the same is <> what is better to use?
Thank you
November 17, 2011 at 2:04 pm
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
December 5, 2011 at 9:20 am
Thank you
December 5, 2011 at 10:53 am
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
December 5, 2011 at 11:15 am
!= seems easier to read to me, but I'm not sure it matters.
December 6, 2011 at 4:38 am
In My Point != Is the Best Compared To <>
December 6, 2011 at 5:18 am
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
December 6, 2011 at 5:35 am
!= and <> are same, it just depends on your coding style, whatever you like :cool:.
December 6, 2011 at 6:20 am
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
December 6, 2011 at 11:59 am
You will probably find that <> is just a little bit easier for others to understand since it is more common.
Todd Fifield
December 7, 2011 at 3:09 am
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
December 7, 2011 at 4:15 am
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