3 ms·
I think the convergence here is toward 'automatically discoverable types'. For python et al this means type annotation (because it's extremely difficult for dis
by morei 6y ago
I think the convergence here is toward 'automatically discoverable types'. For python et al this means type annotation (because it's extremely difficult for discover types otherwise).
For C++ et al this is things like the 'auto' keyword that allow skipping the type specification where the compiler can work it out.
The end-game is specifying just enough type information that it's still understandable to both humans and compilers.
- throwaway189262 6y agoTypescript is extremely good at this. Rust is pretty good. Even Java is okay now. I firmly believe type inference is the future. Most objects in dynamic languages are statically typed anyways, the type just isn't exposed at compile time.
- hhas01 6y agoType inference is good, but it’s not a full answer. For instance, how often do you declare a variable as `int`, when what you really want to say is “an integer in the range 0...100”? A few languages (e.g. Eiffel) provide a formal mechanism for declaring these sorts of constraints, but most don’t, and you end up putting what should be declarative type-level information into the body of your code instead. And then there’s “cutting-edge” stuff like dependent types, where you really want to express one argument’s type in terms of another argument’s, a classic example being an array indexing method, where you really want to declare the index at compile time as an integer in the range `0..<array.length`, and let the type system propagate that rule and its implications throughout the code that uses it. Whereas most “modern” languages chuck a run-time error if you’re lucky; or just ralph and dump stack like some antiquated 1970s throwback (yeah, looking at you, Apple’s Swift). 3/10 Could do much better.
- smichel17 6y agoHuh. I generally enjoy Typescript, but have been frustrated by its inference at times, particularly with regard to generics -- there are places where it will do fine if you pass an arrow function directly, but if you pull it out into a const, the compiler will no longer be able to infer types (and thus fails to compile if you have noImplicitAny enabled).
- throwaway189262 6y agoI've found it's inference to be great, but the error messages GCC-like