|
|
|
|
|
by mathw
3266 days ago
|
|
Type annotations are brilliant for documentation, and it does matter if they're checked or not, because otherwise they're just comments, and we all know comments become wrong over time. If the compiler doesn't enforce your type annotations you can't trust them. The sweet spot for me at the moment is a language which is fundamentally static but has good type inference so that you don't actually have to mention types all the time. Haskell's pretty good at this, although because it's possible to write many Haskell programs without actually mentioning a single type anywhere it can be a pain to read the results. Rust deliberately constrained type inference so that you have to have type annotations on functions, which makes sure your interfaces don't get too murky when reading the code. I'll go with the idea in another reply that static typing really starts to show its benefit in long-lived code bases under maintenance. Certainly a static type checker makes refactoring a lot easier, in my experience. |
|
Note that I wrote statically checked. You can also check them at runtime (basically as a form of Design by Contract), which is what Dart does at the moment.