Hacker News new | past | comments | ask | show | jobs | submit login

The type system is what the compiler (or interpreter) knows about your program. Sophisticated type systems know a lot, and can tell you a lot. Sophisticated does not mean typing a lot.

When building code for the long term, you really want to focus on techniques that make it impossible to misuse an API, whenever it's possible to do that. This article nicely calls out one such technique.

Generic typing can be used to (try to) force the consumer of an API into correct usage. Judicious use of final and abstract in the land of Java can be used force/guide eventual overriders of an abstract class down the right path -- they'll get compilation errors if they don't at least implement the right methods.

Whenever you find yourself writing an assert method, take a beat and figure out if the type system could have turned that into a compilation error instead.




"The type system is what the compiler (or interpreter) knows about your program."

Compilers know a lot more than just what is represented in "the type system" (as it's typically thought of, anyway). Control flow (basic block analysis, &c) for instance. Which isn't really taking away from your larger point - certainly, things represented in the type system are things the compiler will know about.

"Whenever you find yourself writing an assert method, take a beat and figure out if the type system could have turned that into a compilation error instead."

Possibly with a _Static_assert (or static_assert) as if C11 (/C++11)! Obviously there are substantial limitations still, but it's great to be able to pull more to compile time cleanly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: