Overview of Hack Language
- Static typing: With static typing, one may associate the data type of the variable while defining the variable. This is not present in existing versions of PHP. Thus, following becomes possible with Hack:private string $x = ”;
- Generics: Generics allow classes and methods to be parameterized (i.e., a type associated when a class is instantiated or a method is called) in the same vein as statically type languages like C# and Java).
- Nullable Types: Nullable types allows a safer way to deal with nulls and is very useful for primitive types that don’t generally allow null as one of their values, such as bool and int (using ?bool and ?int respectively).
- Collections: One can now create parameterized collections Vector, Map, Set etc that is meant to store/contain pre-defined types of objects conforming to the policy set by the container.
Mind you that programs written in Hack language would need HHVM, an open-source virtual machine to run. It would not run with PHP.exe.
Why Hack may Fail to Fly?
Following are some of the reasons, in my opinion, due to which HACK may fail to fly with average php developers:
It is a general notion in developers’ community that they prefer to go with adoption of technologies including programming languages which is supported/driven by community rather than a specific organization such as Facebook, Google etc although they make the technology open-source. That said, there have been many frameworks that were open sourced by large companies such as Facebook, Google, Twitter etc which were very well received by developers community at large. However, if it comes down to something such as programming language such as PHP, which has been driven by a large community, this becomes a different ball game all together.
On the similar lines, the very fact that the language is supported by one company may not be good enough reason for PHP developer community to accept as you never really know when they would supporting adding enhancements to the language.
Why Not Use Java & the Likes?
Many features such as nullable types, static typing, generics, collections etc, bringing greater capability to PHP, seem to be motivated from strongly typed languages such as Java & C#. The primary reasons being cited for adding some of these features are some of the following:
- The need to be able to release more than once a day vis-a-vis lesser time spent in testing by avoiding bugs upfront arising due to issues such as invocation of methods on null objects only getting caught at runtime, lack of clarity on object types on whom methods are invoked etc.
- Ease of maintainability as code gets easier to change due to features such as static typing, generics etc.
I, myself, being both a JAVA and PHP developer would prefer to use PHP with all its so-called shortcomings rather than HACK just because of its characteristic such as simplicity and rapid development.
This is my personal opinion with absolutely no intention to disregard HACK and I would love to hear you think.
He has also authored the book, Building Web Apps with Spring 5 and Angular.
Latest posts by Ajitesh Kumar (see all)
- Unit Tests & Data Coverage for Machine Learning Models - May 11, 2019
- ML Models Confusion Matrix Explained with Examples - March 30, 2019
- Machine Learning Cheat sheet (Stanford) - March 23, 2019