3 ms·
You can have static types with type inference. I would actually prefer static typing if I did not have to annotate everything. But there are convenience trade-o
by z3t4 8y ago
You can have static types with type inference. I would actually prefer static typing if I did not have to annotate everything. But there are convenience trade-offs like not having to cast when you actually mean to concatenate the number with a string.
- munificent 8y agoNo, inference doesn't have anything to do with it. Inference is easy. The challenge is around the runtime representation of types. Almost all widely used statically typed languages maintain soundness by deferring some type checks to runtime. C++ has dynamic_cast. Java has ClassCastException and ArrayStoreException. C# has something similar. When you add gradual typing where values and functions from untyped code can flow into regions of typed code, you need even more runtime validation to ensure you don't get uncaught type errors in your typed code. The difficult then is figuring out how to represent those types efficiently, what types to reify, etc. It's really really difficult.
- z3t4 8y agoMost people talk about catching errors, but I think the the biggest benefit with static types is performance - as it makes the code easier to optimize. With TypeScript you do not get that benefit. Maybe we will see a new variant of "use asm" for JavaScript, but more human friendly. I really wish TypeScript would have used type inference instead of annotations, and only have a type-checker, and not transpile. JavaScript is already strongly typed. And a completely static type system is a pipe dream, as anything connected to the real world have to deal with chaos.