Hacker News new | ask | show | jobs
by msla 1316 days ago
"Strong" as a descriptor makes more sense if you see a type as a kind of contract: You agree that you will only perform these operations on this value, and the language agrees that all of those operations will be well-defined. "Strength" is how difficult it is to disregard those contracts and peel back the abstraction they enforce to get at some underlying representation, possibly all the way down to where "Bits Is Bits" and everything is permitted. You'll notice that this makes Python's type system stronger than the one C++ has, once you get over the idea that Python's types attach to values, not variables.
1 comments

Right, so it's not very rigorously defined; it's kind of a "feeling" about how easy it is to subvert the high-level system, and it only makes sense to describe a language as "strong" in contrast to another language — which is kind of what I'd said originally. ;)

In any case, I think we agree that it's not what the parent comment of mine had intended to refer to!

And it isn't even all that useful as your only metric: A hypothetical language with only strings can have strong typing if it only allows you to do stringly things on those strings and doesn't, for example, allow you to ever see the codepoints as sequences of bytes; however, you'd have to represent everything in that language as strings, so the semantic types of those objects would be purely conceptual, like types in BCPL, where the compiler only knew about machine words, or, indeed, assembly language.

So we have at least three axes: Static vs Dynamic, Weak vs Strong, and Conceptual vs Semantic, where more Semantically-typed languages allow you to represent more of the meaning you're going for in the type system, and have the language enforce semantic rules like not being able to add person-height to person-weight even if they're both integral types.

(Note that my imaginary string-only language is also statically typed of necessity, given that all variables must have type string and no value can ever move from a variable of one type to a variable of another type.)