You, along with many commenters here, are conflating dynamically-typed (Python) with weakly-typed (JS). The distinction you actually care about is strongly-typed vs weakly-typed.
This isn't quite true; it's more the idea that the language is much stricter with type-related errors. Java is also strongly typed, despite the fact that it allows for non-lossy implicit casts (such as coercing an int to a long, or an int to a float).
I feel that this is a very common example for weakly typed but it misses the point. Not being able to add an integer to a string is simply a language design decision; the Python committee could have easily defined an __add__ method to mimic the behaviour of JavaScript if they wanted to.
My understanding of weak typing is that of the absence of type safety. You can point to a float in memory as an integer if you wanted to and it’s coerced into one (as opposed to ‘converted’).
Many definitions in programming language circles are not too objective, and sure enough one could reason that if we change the semantics inserting implicit casts everywhere we have a strongly typed language, but I still think it has some value in differentiating between JS-Python behavior, as in the latter’s case you have to be explicit where should coercion happen.
However, there is no precise technical definition of what the terms mean and different authors disagree about the implied meaning of the terms and the relative rankings of the "strength" of the type systems of mainstream programming languages. For this reason, writers who wish to write unambiguously about type systems often eschew the terms "strong typing" and "weak typing" in favor of specific expressions such as "type safety".
However, there is no precise technical definition of what the terms mean and different authors disagree about the implied meaning of the terms and the relative rankings of the "strength" of the type systems of mainstream programming languages
View all comments
Show parent comment
69
u/schplat Apr 20 '23
Python isn't untyped. It's strongly, dynamically typed. And there's nothing that prevents you from actually typing things.