Re: if statement not working
Euphoria isn't C, or Pascal, or any other language. That's a good thing. But
it doesn't exist in a vaccum, either. And newbies (and myself) seem to be
tripped up by two features in Euphoria.
1. The '=' sign. I've argued against the current implementation until I was
blue in my face. I think the current behavior is more likely to result in
buggy code. In what other language does an '==' cause the program to come to
a hard stop?
The only good thing about this is that it prepares you for C coding, by using
compare() every time you deal with a string. After a while, it becomes second
nature.
But Robert sees this as a feature, and it's not going to change.
2. Using slices on strings. This "gotcha" was a handmine that littered a lot
of my early code. This initially looks like a good idea, until you get a
string shorter than you expected. So you write:
if s[1..3] = "/* "
and the code goes into cardiac arrest if the length of s is less than 3. If
nothing else, Euphoria should offer a substring function that would provide
some safety:
if substr( s, 1, 3 ) = "/* "
Of course, it would have to pad the string that's returned with nulls so the
length would match what was expected, or else *boom*.
Adding short-circuiting helps, but still, I think it's a nasty trap that
could easily turn someone away from using Euphoria.
-- David Cuny
|
Not Categorized, Please Help
|
|