I believe that 1 == true as much as the next nerd, but still, this line: declare(strict_types=1) is that not a bit ironic?
Comparing the PHP 7 and Hack Type Systems
11–20 of 38 posts
Re: Comparing the PHP 7 and Hack Type Systems
#12I believe that 1 == true as much as the next nerd, but still, this line: declare(strict_types=1) is that not a bit ironic?
I think so, too. I know, I am just hating, but to me it seems like they just can not quite change their culture. Even if they implement something clean and elegant like strong typing their hacky past finds a way to slip in. Nevertheless, congrats to them, they actually deliver.
Re: Comparing the PHP 7 and Hack Type Systems
#13Earlier quoted context omitted.
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.
However in this case line 6 is not the problem in any way (as the grandparent is saying). Looks like a bug in the error reporting?
Re: Comparing the PHP 7 and Hack Type Systems
#14It was a "catchable" fatal error (i.e. E_RECOVERABLE_ERROR) in PHP 5.x for typehints. But PHP 7 is changing it to be an Exception instead, and for some reason it currently produces an inaccurate error message in the master branch - it should say "Uncaught exception" (which it is), but that's not been fixed yet. Trunk builds aren't ready for production use, etc.
Re: Comparing the PHP 7 and Hack Type Systems
#15I believe that 1 == true as much as the next nerd, but still, this line: declare(strict_types=1) is that not a bit ironic?
declare(strict_typehints=TRUE);
However, I changed it to the form that you see there because it was shorter. I felt that in the grand scheme of things it's not very important: declare() isn't a function, it's a language construct, and saving 5 chars from something that'll be typed very frequently is probably worth it.Re: Comparing the PHP 7 and Hack Type Systems
#16It'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…
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.
Re: Comparing the PHP 7 and Hack Type Systems
#17Earlier quoted context omitted.
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.
Which Hack does too (static checking). What he describes (logging) can be enabled as an alternative to that. Maybe you should try it?
Re: Comparing the PHP 7 and Hack Type Systems
#18I believe that 1 == true as much as the next nerd, but still, this line: declare(strict_types=1) is that not a bit ironic?
Yes, and as the person who came up with that, I was well aware of the irony. It was originally this: declare(strict_typehints=TRUE); However, I changed it to the form that you see there because it was shorter. I felt that in the grand scheme of things it's not very important: declare() isn't a function, it's a language construct, and saving 5 chars from something that'll be typed very frequently is probably worth it.
This mindset is something that I've personally seen uniquely permeate every layer of the PHP community, more than anywhere else. I'm honestly curious, what makes communities seem to value things like typing less characters over clarity and correctness? The most important thing to me is reducing the amount of mental state needed for a human to read any line of code.
Re: Comparing the PHP 7 and Hack Type Systems
#19Fatal 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
#20It'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…