by jerf · 11y ago · 0 comments
I think other dynamic-type language communities should read this and think really hard. I've said before, I'd rather see a language become the best $LANGUAGE it can possibly be, for whatever that $LANGUAGE is, than try to bolt things on that pull it away from its core focus. Dynamically-typed languages are dynamically typed. Become the best dynamically-typed language you can be, don't bolt less-than-half-assed static typing on to the side. The sum ends up being less than the parts.
And if that means the next ten years is the language slowly fading into history... that is the destiny for all of us anyhow. Let it be with a fantastic dynamic language that was the best it could be, let it be a language that people speak wistfully of twenty years later. Don't make it be remembered as a Frankensteinien monstrosity as it tried to stay current.
This has nothing to do with optional typing at all. It's just the expected problems with an early and slow (2min!) implementation of core.typed.
Other type checkers and inferencers in gradually typed languages don't have these problems, so you cannot generalize.
E.g. Optional types in Common LISP on which Clojure is based on doesn't have these problems. Scala has similar problems, but most other non-JVM based gradually typed languages not.
What about Shen on Clojure?
There are tons of papers with type checkers in the exact same early state, and how they made it fast and more reliable.
We have a medium sized Typescript app (~100k lines), and it takes 7-10 seconds to transpile to JS.
Whenever a change is made, that is 7-10 seconds the watch command is running and I'm not testing my changes in the webapp.
In fact, a slow running grunt watch is why I'm on HN right now in the first place.
Compared with C and C++ build times which are measured in minutes or even hours, 10s is nothing.
The who who recommended Webpack, I can't reply to you for some reason, though I will try it.
Wait, is that 7-10 sec with "tsc --watch"? Or like, the whole shebang for the production build?
I think TypeScript is an extremely impressive tool, and a great example of considering the current environment when designing. The type system can effectively capture pretty much all API designs that see use.
While your points may be valid, this may not be a great example.
On the other hand, there are instances where types are useful, even in dynamically typed languages. One of them is optimizations. The job of a compiler gets much easier if it can assume that a given variable will always be, say, an integer and nothing else.
Don't use a dynamic language when that sort of thing makes a real difference.
To be fair, core.typed is a completely independent, optional library- It does in no way detract from the dynamic nature of the language or affect you in any way if you simply refrain from including it in your project.
Programming in 2015 seems to be in this really weirdly reactionary mode to the problems of the 1990s in so many places. ("Event-based programming" as an escape from 1990s-styles threading is another one.) Umm, well, it's great that we learn from the 1990s as much as we learn from any other decade, but I'm not convinced optional typing solves the problems of 2015.
Even deciding what those "properties of interest" alone may be is very much an open question. Right now, some advanced type systems simply specify those properties that happen to be easy to infer rather than those properties that would be most valuable (i.e. cause the most expensive bugs). And, of course, you still have the halting problem fighting you at some of those most painful points.
For an interesting (though very partial) discussion of the difficulties, see Lamport's Should Your Specification Language Be Typed?[1] It speaks about specification rather than programming language, but once you decide to introduce rich type systems to programming languages (which was not so much in fashion among PL researchers when that paper was written) the problems become similar (and when he says "statically typed programming languages" he means C or Java -- not Haskell). In the conclusion he even hints at optional types:
But typed formalisms that permit automatic type checking are less flexible than set theory. The best way to catch errors may be to treat type declarations as annotations that do not affect the meaning of the specification. If the type system proved to be too inflexible, one could replace it by a different one or simply ignore certain type errors.
[1]: http://research.microsoft.com/en-us/um/people/lamport/pubs/l...
Native gradual typing can be much faster and assuming the language has a decent test suite, cases can quickly be added to uncover those troublesome spots.
Aftermarket gradual typing leads to a lot of information that you could use to significantly improve the performance of the language (hey, we have an int, so let's use native types instead of our language's version), but because they're not native, that typically doesn't happen.
class Point {
has $.x is rw is required;
has $.y is rw is required;
}
Like many dynamic languages, there's nothing to stop you from assigning the string "foo" to one of those attributes, so let's fix that, but go even further and constrain the X and Y coordinates from -10.0 to 10.0. (Note that a "Rat" is a rational number, so it's perfectly precise and doesn't suffer from floating points imprecision): class Point {
subset PointLimit of Rat where -10.0 .. 10.0;
has PointLimit $.x is rw is required;
has PointLimit $.y is rw is required;
}
So what that's done is allowed the dev to declare a new type, PointLimit, on the fly. It must be a number from -10 to 10. And then we have our X and Y attributes: my $point = Point.new( x => -1.2, y => 7.3 );
$point.x = 3.14;
$point.y = -22.0; # Boom! Constraint violationThere's a set of things that are very hard to bolt on after-the-fact that aren't necessarily that expensive if you start with them. This seems to be one of them.