lua-users home
lua-l archive

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


But what if its __concat is also defined?

On Fri, 16 Apr 2010 07:03:04 -0600, spir ☣ <denis.spir@gmail.com> wrote:

On Fri, 16 Apr 2010 11:59:30 +0100
Matthew Wild <mwild1@gmail.com> wrote:

> 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.

Just an opinion:
The issue here is PL types usually are far to be meaningful, they just map to technical/implementation traits, as shown by their common names (eg string, short or float). Numbers or strings can actually represent nearly anything. Say there were kinds of (say) "semantic" types like 'Count' (~cardinal), 'Index' (~ordinal) or 'Measure' (~real). (Names here mirror use case semantics implemented in the types). Then a static language could infer more sensible constraints and perform appropriate conversions (or casts), I guess, even from and to seemingly unrelated types such as (char-)strings. With common PL types, static checking and conversion is for me a source of traps: the programmer must always be very careful. Lua implements more sensible conversions due to specialised operators such as '..'. When a programmer uses this operator, the intent is thus clear because (if not overloaded) the operands must be strings, so that Lua can safely convert numbers. I would even extend this to perform tostring on any object involved in a '..' operation, provided the metatable's __tostring field is defined. (Would be cool for any output, including test and debug ;-)

Denis
________________________________

vit esse estrany ☣

spir.wikidot.com