What are the main differences and advantages between PHP and Hack languages?

Asked

Viewed 717 times

12

I see that the syntax of both are quite similar, but surely they have their differences, after all they are not one.

What are your differences?

I’ll put some items I think are important for the analysis (some optional):

  • paradigms of them;
  • environments that rotate;
  • typing;
  • evolutions;
  • operations;
  • handling errors and exceptions;
  • advantages in general of the one in relation to the other.

Just a summary of the differences and advantages. I will ask new questions according to the answers if necessary.

1 answer

14


I won’t go into very specific details, just a general overview to help understand the differences.

Typing

I’ll start with the typing I believe is the main difference. Hack has static typing, while PHP has dynamic typing. It is quite true that PHP is walking, or almost ready in the basics, to have an optional static typing. Hack will always benefit by having this as the foundation of the language. In fact the language uses the so-called gradual type system where one can use static type, but also the dynamic where it is beneficial. In general type inference is used.

Because of the typing, briefly, there is more reliability in the code, facilitates maintenance in various ways and allows better performance.

Execution environment

It is important to note that PHP is an essentially script and used for web applications. Cross-platform wheel. Hack can be used this way easily and successfully, but it tries to go a little further. It was designed to work with applications that go beyond a script. It is more suitable for different web applications, although there is a lack of experience and libraries to help. It is important to remember that it is mainly used by Facebook. Hack also runs on major platforms.

Hack uses a Jitter that generates code native to the platform you are running. This produces a huge performance gain.

Maturity and ecosystem

Of course Hack was less mature and has an inferior ecosystem. There are situations where PHP is more suitable, even though Hack being a language "more modern".

Paradigm

The basic paradigm of almost all languages is the imperative. PHP and Hack are no different. In PHP object orientation was introduced and is an adaptation to the language. In Hack this is more organic and present more fully. It is a language that fits more to this paradigm.

Error handling

Error handling is similar to the more modern form (use of exceptions) of PHP. In general it does not work as much with the legacy form of PHP errors (until there is compatibility), but it is not encouraged. The implementation in Hack was a little closer to how other languages work.

Incompatibility

Behold some features not supported.

There is a tool that helps convert PHP to Hack.

Evolution

PHP evolutions try to get closer than Hack already has, but not everything will be possible.

Improvements

A new feature in Hack that will hardly have in PHP is the use of generic that is fundamental for static typing to function in its fullness.

Lambda is a feature that works a little differently. Just as callables.

There is support for async, type aliasing, type Constant, shapes, XML support, attributes, enumerations, new entrants, among other resources.

There is great improvement in the library and special support to data collections that are not present in PHP, in particular tuples. Em Hack the array is not used for everything, there are more specialized data structures with better performance, robustness and semantics.

Have a drink in the C source#.

Completion

Hack is an option for those who need more performance, more robustness and development facilities and want to make applications more complex than a set of scripts as most sites are.

Clearly PHP wants to become Hack. One day I talked personally with the creator of PHP and he showed a certain disdain with Hack, but at the same time liked what the language had. Hack has the advantage of not having the legacy to be considered and better thought out. But PHP already has much of what Hack has deployed, sometimes PHP has done worse, for one reason or another, and is likely to have other features soon, some already announced.

Today the language is headed by Eric Lippert, who is one of the most skilled people in computing and with experience in languages that causes envy.

  • +1 For linking my question :D. Kidding, the answer is good :D

  • You think it’s interesting to study this language and you believe it has potential?

  • 3

    It is interesting to study any language when you want to code well. Facebook created it and is using it well. If many people will use it I do not know. People decide to use things by criteria kind of crazy. If everyone is enjoying the novelties of PHP then they should go p/ Hack. If you think PHP was good, you should not accept the modifications made since the original language that was successful is being distorted. So there’s only the herd effect, not the conscious choice of technology.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.