lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Excerpts from Henk Boom's message of Fri Apr 16 04:07:21 +0100 2010:
> I just fixed a subtle bug in my serialization/deserialization
> functions for a data structure, where objects that were serialized
> then deserialized looked identical but behaved slightly differently.
> It was caused by something like this:
> 
> > return 9 < 10
> true
> > return "9" < "10"
> false
> 
> Lesson learned: make sure to use tonumber() on numbers you extract
> from strings...
> 

Always :)

> It also boost the importance of frequent type checking in my mind, and
> makes me hate automatic string->number coercion a little bit more :p
> 

Eh? Why? If Lua had converted those strings to numbers then you wouldn't
have had a problem, would you? :)

mystring1 < mystring2 is also perfectly valid thing to do in statically 
typed C, which will also give you a useless answer. In my view type
checking is not a substitute for tests and code reviews. And if you
have those, there is little reason left for strict type checking.

Matthew