14 ms·
That... is pretty much exactly the list of problems I've expected out of optional typing. I think other dynamic-type language communities should read this and
by jerf 11y ago
That... is pretty much exactly the list of problems I've expected out of optional typing.
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.
- outworlder 11y ago> 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. 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.
- Touche 11y ago> 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.
- derefr 11y agoOften the point is that it mostly doesn't, and then in a few rare cases (hot inner loops at scale discovered via profiling) it suddenly does. You can rewrite the inner loop in a different language and call it via FFI... or you can type-annotate it. Which is simpler?
- deleted 11y ago[deleted]
- swah 11y agoDo you think optional typing could work if it was part of the language? Or the problems with it are intrinsic?
- Ovid 11y agoWhen it's native to the language, it's awesome. When it's bolted on as an afterthought, you get articles like this. 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.
- grandalf 11y agowhat do you think is the best implementation of optional typing in a language?
- Ovid 11y agoI can't say, but I love what Perl 6 has done. For example, here's a Point class, with read/write, mandatory attributes: 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 violation
- jerf 11y agoIt would certainly be better if it were in there from the beginning. There'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.
- pathsjs 11y agoAmen to that.
- oskarth 11y agoJust to clarify, core.typed is just a library.
- rurban 11y agoNot at all. This is the list of problems that exist with an overly slow, early and incomplete type checker. 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.
- progman 11y ago> Not at all. This is the list of problems that exist with an overly slow, early and incomplete type checker. What about Shen on Clojure? http://www.shenlanguage.org http://www.shenlanguage.org
- pathsjs 11y agoUh? Scala is not gradually typed, and in fact does not have these problems at all... :-?
- rurban 11y agoBTW, the author talks about this in his Strange Loop talk here: https://www.youtube.com/watch?v=yG9CffLlXx0 https://www.youtube.com/watch?v=yG9CffLlXx0 There are tons of papers with type checkers in the exact same early state, and how they made it fast and more reliable.
- fernandezpablo 11y agoI disagree. Typescript is an excellent example of an optional static type system that works great. It has none of the 3 problems the OP describes: it's fast, it nicely encompasses the whole language and the Definitely Typed repository includes a TON of 3rd party library type definitions.
- masterj 11y agoIt's competitor from facebook (http://flowtype.org/ http://flowtype.org/) is also really fast during development as well, even for sweeping changes across big sections of the code base.
- rtpg 11y agoagreed on TS, we're using it extensively in production to great effect. 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.
- softawre 11y agoHow big is your Typescript project? Because when I read the first paragraph of this I cringed and knew where they were going. 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.
- maineldc 11y agoThe article's code base is also ~100K lines (of clojure) and the type checker runs for 2 mins, so it feels safe to say that Typescript's checking is an order of magnitude faster, right?
- softawre 11y agoI guess so. The who who recommended Webpack, I can't reply to you for some reason, though I will try it.
- pron 11y agoFirst of all, adding optional static typing is not "trying to stay current". You may be surprised (I certainly was), but at the last ECOOP it was very clear that the typed/untyped/optionally-typed debate is very much alive and well. Second, optional typing in itself is a hot topic (regardless of the merits of static typing), with some very interesting work. See, e.g. the extremely-powerful-but-not-yet-production-ready pluggable type systems supported by Java 8: http://types.cs.washington.edu/checker-framework/current/checker-framework-manual.html http://types.cs.washington.edu/checker-framework/current/che..., or Gilad Bracha's optional types in Dart.
- jerf 11y agoI'm generally underwhelmed with the whole idea of optional typing in general, because it seems like a solution to the problem of sucky static type systems. The solution is, static type systems that don't suck. If you have that, optional typing seems a lot less interesting. 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.
- pron 11y agoThe search for type-systems-that-don't-suck is very much ongoing and there's no solution in sight. You need to find one that is 1/ understandable and palatable to the human mind, 2/ powerful enough to specify properties of interest and 3/ can be inferred as much as possible to reduce effort. 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/lamport-types.pdf http://research.microsoft.com/en-us/um/people/lamport/pubs/l...
- erichmond 11y agoCore.typed is a library, not an extension to the language itself. It's completely optional and is not related to clojure.core at all. While your points may be valid, this may not be a great example.
- drcode 11y ago> don't bolt less-than-half-assed static typing on to the side. 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.