Hacker News new | ask | show | jobs
by openasocket 3781 days ago
I disagree: strong and weak typing are fairly well defined terms. I'm going off the definition given in "Programming Language Pragmatics," which states "a language is strongly typed if it never allows an operation to be applied to an object that does not support it; a language is said to be statically typed if it enforces strong typing at compile time."
4 comments

No, the parent comment is correct: formally they're meaningless. Those definitions might be fine for casual discussions, but from an academic programming language standpoint they don't correlate to anything meaningful.
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.

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...

Even if you are correct that they are well defined, by that definition Lisp, Ruby, Python, JavaScript and Julia are strongly typed. C, Forth and assembly language are not. So the distinction isn't useful in this discussion.
Javascript is probably one of the weakest typed languages out there. {}+{}, []+[], {}+[] are all completely valid operations in javascript that cause all kinds of implicit coercions. And assembly language is very strongly typed: it just has a very simple type system.

As for Julia, I'm not sure how strongly or weakly typed it is, but I would probably put it at around the same level as Java.

Well, Forth is considered untyped, which I think is apt: it's basically bytes on a stack passed between words, with semantic meaning completely in the programmer's head and hopefully well-documented.

With that in mind, shouldn't we expect it to be a good base case for describing the "weakest typed" language?

Type safety is the property that no primitive operation ever applies to values of the wrong type.

"Programming Languages: Application and Interpretation" Shriram Krishnamurthi, 2003.