5 ms·
> Static typing requests you to explicitly declare types. You are confusing explicit typing with static typing. "Static" means "compile-time checking". "Dynami
by rkido 9y ago
> Static typing requests you to explicitly declare types.
You are confusing explicit typing with static typing. "Static" means "compile-time checking". "Dynamic" means "defer checks to run-time". Some language implementations can disable run-time type checking if optional type annotations are added, such as in Typed Racket.
In other words, all the following combinations are possible:
- Implicit + dynamic + strong: Python
- Implicit + dynamic + weak: JavaScript
- Implicit + static + strong: Standard ML without type annotations
- Explicit + dynamic + strong: Elixir with type annotations
- Explicit + static + strong: Java
- Explicit + static + weak: C
I struggle to come up with examples for these...
- Implicit + static + weak
- Explicit + dynamic + weak
... but I'm sure they exist, perhaps as historical languages from when type systems were less sophisticated. After all, "strong" and "weak" are entirely relative, constantly in flux, and exist on a continuum. In a couple decades, anything lacking dependent types might perhaps be considered "weakly typed".
- evincarofautumn 9y agoFor explicit+dynamic+weak, I think ActionScript 3 fits the bill. The language is dynamically typed by default (an un-annotated variable has the dynamic type, “*”), but you can add type annotations, which are used to guide the implicit dynamic type conversions inherited from AS3’s ECMAScript roots. And the type system has some inherent weakness, such as the fact that the “Function” type isn’t generic: it enforces that a value is a function, but doesn’t enforce anything about its parameter types or return type.
- continuational 9y agoJava is not strongly typed; I can add an int to a String, and I can compare Apples to Oranges. It's as weak as JavaScript, just statically typed.
- flavio81 9y ago> "Static" means "compile-time checking". "Dynamic" means "defer checks to run-time" It is not really about checking, it's about allocation/binding. Static typing, for binding a variable, requires declaring the type of the data, this can be explicit (as in C++) or inferred from another value where the type was declared (as in C++ with 'auto' or as in Haskell). Dynamic typing does not require a type declaration. You can bind an unassigned variable and then assign a value later, without having to declare the variable type.
- rkido 9y agoI'm no expert on type systems so my definitions are not meant to be theoretically correct, just to describe the practical implications of static and dynamic typing. What you're talking about seems to be more related to how type systems are implemented, i.e. that dynamically-typed languages are "unityped", such as the one and only "static type" of Python being the PyObject. Thus, when you "bind an unassigned variable and then assign a value later", you're actually implicitly declaring the type to be PyObject. But it is deceptive to define type systems purely in terms of this implementation detail, because then it would appear as if dynamically-typed languages are untyped (i.e. "everything is one type" is the same as saying "there are no types"). Since we know languages like Python do some type-checking at run-time despite everything being a PyObject, it is more useful, I think, to think of these languages in terms of the practical result rather than in terms of the implementation. But if that's not what you're saying, I apologize.