|
|
|
|
|
by jwatzman
4067 days ago
|
|
It's worth pulling out what I think is the most fundamental difference between the two type systems, from the end of the article: After writing a couple small programs in Hack I've realized that it's not types themselves that make writing Hack enjoyable: it's the tight feedback loop Hack creates between the machine and myself. Integrating the Hack type checker into my editor means that my entire codebase is analyzed in a split second as soon as I save a file. This immediately surfaces any dumb, or subtle mistakes I made. I find myself writing code fearlessly: when I forget what a function returns, I just write code that calls it with what I think it returns. If I'm wrong, the type checker will tell me immediately. I can fix it quickly, and move on. Hack's type system is static -- it's enforced by a static analysis tool that instantly reports errors in all of your code. PHP can only report errors that it actually encounters at runtime. Along with the "fearlessness" above, it also means that you might miss you forgot to check for a null in an error case... until it explodes at runtime in production. Hack's static type system can mechanically check for all of these immediately. |
|
Of course, a tool for PHP 7 can only go so far, because PHP 7's type hints aren't sufficient to cover everything, unlike Hack which has things like nullable support.