Hacker News new | ask | show | jobs
by openasocket 3775 days ago
The closest concept I can think of is the concept of "strong typing," that a value does not change type based on its context, which is a fairly widely used term. It seems like Julia has some form of weak typing, at least between the different numeric primitives, and "type stability" refers to avoiding any usage of weak typing. I don't know a lot about Julia, though, so I could be way off here.
2 comments

"Strong typing" and "weak typing" don't really mean anything:

http://blogs.perl.org/users/ovid/2010/08/what-to-know-before...

You probably mean "static typing" versus "dynamic typing" which I wrote a bit about in the context of Julia here:

http://stackoverflow.com/questions/28078089/is-julia-dynamic...

Basically, I think "type stability" hasn't really been a thing in the past because in dynamic languages, people have traditionally not cared about ensuring that return types are predictable based on argument types, and in static languages, a program is incorrect if that's not the case. As people care more and more about being able to statically predict the behavior of programs in dynamic languages, the concept of type-stability in dynamic languages becomes increasingly important.

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

So what is “strong typing”? This appears to be a meaningless phrase, and people often use it in a non-sensical fashion. To some it seems to mean “The language has a type checker”. To others it means “The language is sound” (that is, the type checker and run-time system are related). To most, it seems to just mean, “A language like Pascal, C or Java, related in a way I can’t quite make precise”.

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