Hi Craig,
Fun philosophical discussion
For what it's worth i would argue that
arithmetically 003 and 3.0 are the same, but
programmatically these are not - not because there is a difference in mathematical value, but because of a difference in
type of variable.
Imagine this scenario: You may receive data of
unknown type from some process and stick it in a variable.
If the type of data is an integer (eg. 003, 052 or 111) then it signifies an error code.
If the type of data is a float (decimal, eg 0.001, 1.5, 3.8, or yes, 1.0 ) then it's the result of a computation.
Your introspection includes the code:
If it's an integer - no problem, in this fictitious example you would act on the error code received.
But if this the value of a result, that say in this case could have been 1.1, 1.2, 1.5 but in this case returns 1.0, then that's a problem as
integer returns true. Which means in this particular example your code would assess this as an error code, not a result value.
Arithmetically in LiveCode these are these are of course the same and it matters not when you perform arithmetic with these numbers. But if you have decisions based on
type of data, this will lead to issues.
My issue is that the
integer keyword fails to recognise this, which would be important in the above example (where you need to know the type of variable you're dealing with).
Many typed languages are clever and can infer the data type. In Swift, you can type
Code: Select all
var tDouble = 2.0 //infers the data type is double (ie decimal)
var tInteger = 2 //infers the data type is integer
As LiveCode is typeless language it of course doesn't make any difference when performing arithmetic (whereas in typed languages this would cause crashes), but if your decision making is based on
data type, then the
integer keyword failing this way is a problem...
LiveCode does an excellent job at shielding devs from many of the issues with data types, but there are tradeoffs, like in the example above.
There's a very nerdy write up on data types in programming languages on
Wikipedia but i'm sure there are simpler resources online -- they would all say the same as above. But thankfully this doesn't really affect LiveCode coding in most circumstances.