Hacker News new | ask | show | jobs
by hyperpape 3778 days ago
I happen to think that there are meaningful things you can express by saying "Strong Typing" or "Weak Typing" (https://news.ycombinator.com/item?id=9256695), though "well defined" might be stretching it. However, I don't like this definition at all.

Both JavaScript and Python prohibit operations on types that don't support them. They both have TypeErrors (or something similar) that are thrown at runtime for certain operations, while others produce a result.

The difference is just that JavaScript allows a bunch of operations that Python prohibits, including several that serve almost no purpose.

Is allowing 1 + "1" allowing an operation on a type that doesn't support it, or does your language just allow adding numbers and strings? There is no principled way to answer that question.

1 comments

The strong vs. weak typing axis is a more of a spectrum. Virtually every language has some form of weak typing, especially with the numeric types. I guess the litmus test for whether or not a given operation allows weak typing is if it is equivalent to implicit coercion. Languages like Java allow the operation "one" + 1, which is equivalent to "one" + (1).toString() (basically, you'd have to box the integer first to actually make this compile), so it is performing an implicit coercion, and thus an example of weak typing. In the same situation Python would throw an error, and is thus an example of strong typing.

That litmus test is probably not enough to make a true formal definition, but does allow you to make objective comparisons between languages for certain operations.

By this definition, Julia is as strongly typed as possible: no automatic promotion or conversion is ever done for anything, including numbers. What appears to be "weak typing" is a clever application of multiple dispatch system with built-in fallback methods for numeric operations. See

http://docs.julialang.org/en/latest/manual/conversion-and-pr...