Hacker News new | ask | show | jobs
by aslamc 2148 days ago
Is there a good reason to still use php when you can use hacklang (https://hacklang.org/) which has much stronger type system. Some would even call it php++.
4 comments

A lot of what Hack introduced to the PHP community has become available in suitably forward-thinking ways to allow for a sensible amount of backwards compatibility and are opt-in.

For example, you can set strict typing on a per-file basis.

`declare(strict_types=1);`

I believe that the performance difference between the two is negligible now too. So it really just comes down to personal preference/platform legacy.

But Hack is on a different path which is potentially going to make it harder to share code between PHP and Hack.

PHP still has by far the larger community.

Given the choice today, I’d run with PHP.

the only thing that sucks about strict typing is that there's no way to toggle it globally. so if you want to transition a codebase that's simultaneously actively being developed in other ways, you have to mess around with scripts that append it to the start of all php files/remove it again
Nothing that tools like Rector can't help you with.

I believe this extra step is incredibly important, given most of your dependencies you won't control and forcing strict types to them is not very clever IMO.

I guess it wouldn't work if your dependencies weren't easily seperable from the rest of the code. in this case there are no dependencies, it's all custom cobbled together, for better or worse
Hack isn’t still commonly used outside of FB, and for the right reasons - the PHP community is much bigger. Very few projects test for Hack compatibility, and the performance gains aren’t worth it these days (they were 5 years ago, but not so much these days)
Having "much stronger" type system cannot be anyone's definitive reason for deciding to go with Hacklang instead of PHP.

Type system doesn't guarantee that the programmer will utilize it properly, produce optimal code or even figure out the problem that is being solved by writing an algorithm.

You also need to pay attention to the ecosystem, problems that come with HHVM, the fact you're undoubtedly tying yourself with Facebook and what you're gaining / losing with the decision to go with a fork of PHP.

If you’re building an app to run on other people’s servers, vanilla PHP is much more widely available :(

(Sad because I use Hack in my day job and PHP for my open source projects, and find Hack way more pleasant and productive)

Hacklang diverged from PHP proper a while ago, but I haven't validated what this actually means. I know interoperability wasn't guaranteed, but with Hack at your work are you able to use composer packages - i.e. Symfony components? The ecosystem around pure Hack packages or frameworks appears quite small/niche.