12 ms·
A strongly typed dynamic language will raise an type error if you for instance try to add two incompatible types, for instance in python Python 3.9.0 (defaul
by hultner 5y ago
A strongly typed dynamic language will raise an type error if you for instance try to add two incompatible types, for instance in python
Python 3.9.0 (default, Oct 10 2020, 11:40:52)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1+"1"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +:
'int' and 'str'
While a weakly typed dynamic language like JS will allow for it
Welcome to Node.js v16.0.0.
Type ".help" for more information.
> 1 + "1"
'11'
- dragonwriter 5y agoIf the language allows it the types are (ipso facto) not incompatible; “weak typing” is more a subjective statement about how well a language lines up with the speakers mental model of what types should be compatible than an objective one about falsifiable properties of the type system.
- DaiPlusPlus 5y agoI contend there is no such thing as "weakly-typed" because it suggests it exists in opposition to strongly-typed systems - but instead I feel "weakly-typing" should be considered the absence of type-correctness checking by either the compiler nor the runtime - and that the term "weakly typed" and related should not be used to refer to languages with plenty of implicit conversion between types, because in those languages (like JS) the implicit conversions are very, very, well-defined and predictable ahead of time - TypeScript models JavaScript's implicit type conversions accurately, too. JavaScript's more forgiving, and often surprising, implicit conversions are still rigidly-defined . Remember that implicit conversions should never (ostensibly) throw any exception or cause any errors because implicit conversion should always succeed because it should only be used to represent an obvious and safe narrowing-conversion. A narrowing-conversion necessarily involves data-loss, but it's safe because all of the data needed by the rest of the program is being provably retained.
- pydry 5y agoWeakly typed / strongly typed are not really useful terms - there are too many separate definitions, all of which are pretty much equally valid.
- blacktriangle 5y agoI thought we were all agreed that the strong - weak type axis was to what degree the language automatically converts types?
- igouy 5y ago'Indeed, the phrases are not only poorly defined, they are also wrong, because the problem is not with the “strength” of the type checker but rather with the nature of the run-time system that backs them. The phrases are even more wrong because they fail to account for whether or not a theorem backs the type system.' 29.5 Types Versus Safety "Programming and Programming Languages" https://papl.cs.brown.edu/2020/safety-soundness.html#%28part._.Types_.Versus_.Safety%29 https://papl.cs.brown.edu/2020/safety-soundness.html#%28part...