
07-24-2005, 07:11 AM
|
|
Graal Administration
|
Join Date: Jan 2000
Location: Admins
Posts: 11,693
|
|
Need your opinion for a technical question
|
In the new scripting engine there is a problem right now: operations that check if a variable is greater or less than another variable work for both numbers and strings, but have different results depending on the type of the variable:
"Atlantis"<"Zoo", 5>3, but also "123"<"4", 123>4,
because strings are alphabetically sorted, numbers by numeric value. Currently you need to at least convert one of the two variables too numeric type (using the int() or float() function) to enforce comparison by numeric value.
Question is: should those operators (<,<=,>,>=) and functions (min,max) always use numeric values for comparison and we add a new function strcmp or similar for comparing strings,
or we keep it like it is but need to enforice numeric comparison by using int() or float().
I would prefer the first option, always do numeric comparison, because string comparison is not needed very often, but often variables are transferred as string (e.g. when sent by client) and if you then accidently compare two client vars or similar and don't use int() or float() then you get bad values and don't directly know why.
For the equality operators (==,!=) we can keep compatibility with all variable types since numeric variables are the same no matter if you compare their numeric value or their string representation. |
|
|
|