ITT: Lots of people confusing strong/weak typing with dynamic/static typing. Lots of opinions of questionable quality in here. Here's a rundown of typing methods:
Strong typing means values are of specific types that can only be used in well-defined ways. Weak typing means data is loose and can be used in different ways. In Clojure (strong typing), an operation that expects an integer can only operate on an integer, and will throw an error if fed anything else. In C (weak typing), an integer can be passed around and used as an integer, a pointer, or a character, depending on the strictness of the compiler; if not strict, it won't complain at all.
Dynamic typing means that the types of identifiers and parameters are flexible. Static typing means they must match 1:1. In Clojure (dynamic typing), a function that takes one parameter and operates on it as if it were a collection can operate on any kind of collection passed in, but if an integer is passed in, the function will fail at runtime. In Java (static typing), the function's argument must have a type; if it expects a List, passing it an integer will throw a compile-time error.
Clojure, Ruby, and Python are dynamic and strongly typed.
Java, C#, F#, Ocaml, Haskell, and Rust are static and strongly typed.
C and C++ are static and weakly typed.
JavaScript is dynamic and weakly typed.
Type annotations != static typing. For example, F# is statically typed but can be used without type annotations in most situations; this is known as type inference, where the compiler tries to figure out the type of the identifier given the context and hold the programmer to that type.
Likely because union is constructing the set union expecting only a collection/sequence. So the function doesn't care if it gets a list, vector, sequence, or possibly even a map. But it has to be a collection which can be iterated over. This is still strong typing using interfaces to expose common, generic mechanisms.
For true weak typing, let's imagine a very lenient C compiler. Say we're passing in a pointer and its size as two parameters, similar to how one would pass in an array, and the function simply assuming it's an array. If that pointer was not to an actual array or the size isn't correct, the union function could iterate over all of the contents of memory until it breaches its sandbox, makes an illegal access, or some undefined memory operation which the OS will intervene to stop. In a strongly typed language, collections are first-class types with strict access limitations and iteration mechanisms to avoid such errors.
15
u/netbioserror Jun 12 '16 edited Jun 12 '16
ITT: Lots of people confusing strong/weak typing with dynamic/static typing. Lots of opinions of questionable quality in here. Here's a rundown of typing methods:
Strong typing means values are of specific types that can only be used in well-defined ways. Weak typing means data is loose and can be used in different ways. In Clojure (strong typing), an operation that expects an integer can only operate on an integer, and will throw an error if fed anything else. In C (weak typing), an integer can be passed around and used as an integer, a pointer, or a character, depending on the strictness of the compiler; if not strict, it won't complain at all.
Dynamic typing means that the types of identifiers and parameters are flexible. Static typing means they must match 1:1. In Clojure (dynamic typing), a function that takes one parameter and operates on it as if it were a collection can operate on any kind of collection passed in, but if an integer is passed in, the function will fail at runtime. In Java (static typing), the function's argument must have a type; if it expects a List, passing it an integer will throw a compile-time error.
Clojure, Ruby, and Python are dynamic and strongly typed.
Java, C#, F#, Ocaml, Haskell, and Rust are static and strongly typed.
C and C++ are static and weakly typed.
JavaScript is dynamic and weakly typed.
Type annotations != static typing. For example, F# is statically typed but can be used without type annotations in most situations; this is known as type inference, where the compiler tries to figure out the type of the identifier given the context and hold the programmer to that type.