Strength of typing in Lua language

Asked

Viewed 225 times

4

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

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site

1 answer

5

There is no reliable source of what the strength of typing is. I have seen several definitions and many people consider that it has no relevance. Some say, and this seems to be clearly wrong, that dynamic and weak typing are the same thing, as well as static and strong typing.

The understanding that I see more around, and words may not be the most appropriate, is that weak typing allows a value of one kind, and every value has a type, to be interpreted as if it were of another kind. This may be only use differently or may be by an implicit conversion (the latter there are controversies).

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

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

I don’t 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. 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 without chance of error (although this is not an absolute truth, it has types that do not produce significant text).

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.