Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using == vs =
Message
From
06/11/2015 16:20:51
 
 
To
06/11/2015 04:37:41
Walter Meester
HoogkarspelNetherlands
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01627149
Message ID:
01627188
Views:
70
>>>>>Just encountered a bug in our software releated to the use of = when set exact is set to off.
>>>>>
>>>>>I Know I should be using == in those cases where comparing strings of different lenght, but just a small test made me wonder.
>>>>>
>>>>>Is there any reason I should not use == for any comparison in VFP? It seems to work for any datatype.
>>>>>
>>>>>Is there any gotcha using == as a standard?
>>>>>
>>>>>
>>>>>Walter,
>>>>
>>>>Not that I am aware of, I know people who do that all the time in order to differentiate assignments from comparisons.
>>>
>>>Which I find a good argument in itself. I just wonder why it has taken me more thaw 20 years to draw that conclusion.
>>
>>It's definitely safer to use == where you need to rely on an exact comparison.
>>
>>My understanding is == is a little slower than =, and there can be speed/Rushmore optimization issues with indexes e.g. if you have a column MyCharCol that is indexed, and you have WHERE MyCharCol == "SomeValue" ... in a SELECT, ISTR it's not fully optimizable.
>>
>>So, safer but a little slower.
>
>I did not look into rushmore and to be honest I'm not that concerned about that one. I'm not dealing with VFP databases 99% of the time.
>As for speed. It does not matter AFAICS. The following program does not give me any indication (after running it 10 times) that it is slower. In fact if there is a difference it seems to slightly faster (up to 5%).
>
>
>
>CLEAR 
>SET EXACT OFF
>
>? "Non Equal values"
>
>nVal1 = 1
>nVal2 = 2
>
>nSec = SECONDS()
>
>FOR nT = 1 TO 1000000
>	nRet = nVal1 = nVal2
>ENDFOR
>
>? "numeric using = ",SECONDS() - nSec
>
>nSec = SECONDS()
>
>FOR nT = 1 TO 1000000
>	nRet = nVal1 == nVal2
>ENDFOR
>
>? "numeric using == ",SECONDS() - nSec
>
>
>nVal1 = "MyVal1"
>nVal2 = "MyVal2"
>
>nSec = SECONDS()
>
>FOR nT = 1 TO 1000000
>	nRet = nVal1 == nVal2
>ENDFOR
>? "String using == ",SECONDS() - nSec
>
>
>
>nSec = SECONDS()
>
>FOR nT = 1 TO 1000000
>	nRet = nVal1 = nVal2
>ENDFOR
>? "String using = ",SECONDS() - nSec
>
>
>? "Equal values"
>
>nVal1 = 1
>nVal2 = 1
>
>nSec = SECONDS()
>
>FOR nT = 1 TO 1000000
>	nRet = nVal1 = nVal2
>ENDFOR
>
>? "numeric using = ",SECONDS() - nSec
>
>nSec = SECONDS()
>
>FOR nT = 1 TO 1000000
>	nRet = nVal1 == nVal2
>ENDFOR
>
>? "numeric using == ",SECONDS() - nSec
>
>
>nVal1 = "MyVal1"
>nVal2 = "MyVal1"
>
>nSec = SECONDS()
>
>FOR nT = 1 TO 1000000
>	nRet = nVal1 == nVal2
>ENDFOR
>? "String using == ",SECONDS() - nSec
>
>
>
>nSec = SECONDS()
>
>FOR nT = 1 TO 1000000
>	nRet = nVal1 = nVal2
>ENDFOR
>? "String using = ",SECONDS() - nSec
>
>
Without looking at your code, == is supposed to be just an exact *string* comparison: https://msdn.microsoft.com/en-US/library/3b6st626%28v=vs.80%29.aspx . It's interesting that it "works" - or at least doesn't give errors - if used with other data types. I haven't seen it used for other data types in VFP before, although it is a convention in other languages. You're thinking outside the box ;)
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform