Comparing the PHP 7 and Hack Type Systems
1–10 of 38 posts
Re: Comparing the PHP 7 and Hack Type Systems
#2 Fatal error: Argument 1 passed to myLog() must be of the type string, integer given, called in /home/vagrant/basic/main.php on line 9 and defined in /home/vagrant/basic/main.php on line 4
"HHVM says the error occurred on line 6 where PHP says it occurred on line 9. I prefer HHVM's approach here as it shows us where we called the function with the bad data, not where the function is defined that we are calling with bad data."Hrm, PHP is telling you both line 4 and line 9, as where the function is defined and where it's being called with bad data, which is quite nice. In comparison, HHVM is saying line 6, which is a closing brace for the myLog function. In my books, PHP's approach is way way better then HHVM's
Re: Comparing the PHP 7 and Hack Type Systems
#3Fatal error: Argument 1 passed to myLog() must be of the type string, integer given, called in /home/vagrant/basic/main.php on line 9 and defined in /home/vagrant/basic/main.php on line 4 "HHVM says the error occurred on line 6 where PHP says it occurred on line 9. I prefer HHVM's approach here as it shows us where we called the function with the bad data, not where the function is defined that we are calling with ba…
Re: Comparing the PHP 7 and Hack Type Systems
#4Fatal error: Argument 1 passed to myLog() must be of the type string, integer given, called in /home/vagrant/basic/main.php on line 9 and defined in /home/vagrant/basic/main.php on line 4 "HHVM says the error occurred on line 6 where PHP says it occurred on line 9. I prefer HHVM's approach here as it shows us where we called the function with the bad data, not where the function is defined that we are calling with ba…
It's hard to say what is better - oftentimes when you see a large stack trace for an error, it can be difficult to determine where the offending line is, especially on first glance. Personally, I think I agree with the author, but PHP 7 does look to give more information, which can be better in some situations.
Re: Comparing the PHP 7 and Hack Type Systems
#5 function dowork(@?string $w)
You can allow execution to continue but still log the error. It's made me aware of all sorts of edge case bugs that I never would have been able to find before.XHP has allowed me to do the same, by forcing me to write well formed html and I love it
Re: Comparing the PHP 7 and Hack Type Systems
#6I really like writing hack and haven't tried PHP7. It makes a huge difference having types. If you have a function function dowork(@?string $w) You can allow execution to continue but still log the error. It's made me aware of all sorts of edge case bugs that I never would have been able to find before. XHP has allowed me to do the same, by forcing me to write well formed html and I love it
Re: Comparing the PHP 7 and Hack Type Systems
#7After 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.
Re: Comparing the PHP 7 and Hack Type Systems
#8I really like writing hack and haven't tried PHP7. It makes a huge difference having types. If you have a function function dowork(@?string $w) You can allow execution to continue but still log the error. It's made me aware of all sorts of edge case bugs that I never would have been able to find before. XHP has allowed me to do the same, by forcing me to write well formed html and I love it
You should seriously consider trying a language with a more complete and robust type system that is checked at compile time. If you like the fact that these kind of corner cases can be logged, imagine if you can find them before you ever hit them at compile time.
Maybe you should try it?
Re: Comparing the PHP 7 and Hack Type Systems
#9 declare(strict_types=1)
is that not a bit ironic?Re: Comparing the PHP 7 and Hack Type Systems
#10I believe that 1 == true as much as the next nerd, but still, this line: declare(strict_types=1) is that not a bit ironic?
Nevertheless, congrats to them, they actually deliver.