Lua language typing strength

2

Moon has dynamic typing, but after all, is it strongly typed or weakly typed? Each source I consult has a different information, which left me in doubt.

    
asked by anonymous 25.04.2018 / 04:34

1 answer

2

There is no reliable source for typing strength. I have seen several definitions and many people consider it to be irrelevant. There are those who say, and this seems to be clearly wrong, that dynamic and weak typing are the same, as well as static and strong typing.

The understanding that I see more out there, and the words may not be the most appropriate, is that poor typing allows a value of one type, and every value has type, can be interpreted as being of another type. This can only be used differently or it can be by an implicit conversion (the latter is controversial).

Strong typing determines that the value is only used by the type it was designed for and does not relate to other types in an implicit way (controversially).

It is possible to be considered strong when the language only accepts reinterpretations / conversions that have obvious and correct meaning, and is weak when it allows any situation of using the value differently than it should, ie, it tries to do the operation within of some criterion, even if the result is not appropriate.

I do not know if we can say that all languages are 100% strong or weak in typing.

My understanding is that Lua has essentially strong typing. There are some exceptions The addition and concatenation operators make implicit conversions.

I agree that concatenation turns everything into string , many languages consider string as a universal type that any value can be converted with no chance of error (although this is not a absolute truth, have types that do not produce meaningful text).

Since the addition operator can not be confused with concatenation, I think other types should be converted to numbers when using it, but I see some problem because the operation will not always succeed. But this is debated, a division by zero can also generate error, an overflow can also, and it is better to be generated error instead of producing a wrong result.

    
25.04.2018 / 05:11