Hack – The Programming Language Powering Facebook

Hack is the new language behind Facebook, which remains the most popular social network today. It is a web programming language invented and recently open-sourced by Facebook. The company claims that Hack helps programmers to code more quickly and easily avoid errors early on.

Hack is designed to build complex websites swiftly while ensuring the site’s source code is well-organized and relatively error-free. Its “safety net” features allow programmers to write safer code, which reduces the risk of encountering problems later.

In this post, we’ll explore Hack and some of its features that are arguably better than PHP, the current leading web programming language used for most websites. Hack is built to run on Facebook’s HHVM virtual machine, which is known for its superior performance.

Learning Programming: 10 Misconceptions That Are Not True

Learning Programming: 10 Misconceptions That Are Not True

There are plenty of misconceptions and myths surrounding the art of programming. Many people view it as a... Read more

The Dynamics of a Problem

Back in 2003, when Mark Zuckerberg started building Facebook, he used a web development language called “PHP”. It was the most popular and (relatively) easy programming language at the time to create dynamic websites quickly.

PHP is a dynamically-typed language, which means you don’t need to spend time defining variables, and once you finish your code, you can almost run it instantly. This makes coding easier and reduces development time and effort, but significantly increases the chances of encountering errors, which only become apparent during execution.

30 Common Reactions Programmers Have When Things Go Wrong

30 Common Reactions Programmers Have When Things Go Wrong

Developing applications can be a very stressful job. Nobody is perfect, and running into buggy code is fairly... Read more

Can’t Afford to Have Mistakes

This further intensifies the problem because you need to run the code to find errors, unlike statically-typed languages. These errors continue to grow with the size of the codebase. Small projects might not face major issues, but with a large codebase containing 5 errors per thousand lines of code, potentially up to 5000 errors, that’s a lot to debug.

The situation worsens for Cloud-scale companies like Facebook, where thousands of programmers write and ship new code every day. They can’t afford to have errors in their code, which could lead to user data being compromised. So, what can be done?

10 Programming Habits Developers Should Adopt

10 Programming Habits Developers Should Adopt

These outcomes can bring down our confidence but in fact, they can be solved with proper development practices.... Read more

Reinventing the Wheel

Since Facebook’s front-end was mostly written in PHP, switching to a new language would require migrating the entire site code, which is both impractical and unfeasible. Additionally, if the programmers are already accustomed to PHP, this would necessitate a massive overhaul in human resources.

Fortunately, there is a better solution – they reinvented a language, derived from PHP, that can coexist with the traditional language.

“Thus, Hack was born. We believe that it offers the best of both dynamically typed and statically typed languages, and that it will be valuable to projects of all sizes,” it was announced on Facebook’s Engineering blog.

Hack Is Simply Better PHP

Essentially, Hack is “better PHP”. Derived from PHP, it inter-operates seamlessly with PHP for faster and safer web development. You can have a project containing PHP and Hack code side-by-side, and still, the project runs as required. This key feature will attract PHP developers to try Hack and possibly encourage them to gradually migrate their PHP code to Hack.

Hack primarily adds to PHP the power of static typing, along with many more features found in other modern programming languages. It’s a language developed for HHVM (HipHop Virtual Machine), an open-source runtime platform built by Facebook to execute programs written in Hack and PHP.

The Hack and HHVM combo targets one of the foundations of modern web development: rapid app development. Testing and debugging web applications have never been easy, but Hack changes that by allowing programmers to detect errors early without compromising the development cycle of PHP. The conclusion from several tech sites has been that Hack is good news.

Advantages of Hack

The greatest enhancement that Hack provides over PHP is the removal of unnecessary and error-prone features. Hack adds safety nets (without slowing you down) so you make fewer errors. It also adds various features found in modern programming languages, making writing code in Hack enjoyable.

Hack is both a dynamically typed and statically typed web development language, bringing the best of both typed languages. This is called “gradual typing,” a type system that allows variables to be typed either at compile-time or at run-time. It can run your code without compiling – you can edit a file, reload the webpage, and see the changes instantly.

Other Features

Hack includes features such as collections, lambda expressions, run-time enforcement of return types and parameter types, addition of generics, asynchronous programming, and more.

These new features are non-obstructive, so code written using Hack will still look and feel like traditional dynamic code created using PHP. Moreover, engineers will better understand the code as static typing acts a lot like documentation.

What’s Not So Advantageous

The greatest disadvantage of Hack is that it has abandoned the features that make PHP a simpler language for beginners. You cannot embed HTML directly in your source code, and you can’t have code written outside of a function or class. But this is a relatively small problem. While it may deter beginners, PHP programmers will likely find it easy to adapt to Hack and will probably deem the advantages of Hack convincing enough for adoption.

13 Sites to Learn How to Code for Web Developers

13 Sites to Learn How to Code for Web Developers

Gone are the days when programming languages could only be mastered programmers like Bill Gates, who later got... Read more

Facebook has already deployed Hack on its website, which serves more than 1.2 billion people worldwide. “We have deployed Hack at Facebook, and it has been a great success. Over the last year, we have migrated nearly our entire PHP codebase to Hack,” stated the article on the Facebook Engineering blog.

The Future

It will be interesting to see how the PHP community at large adopts this new language. We hope to see Hack supported on other PHP virtual machines and parsers, which will simplify code migration.

An open-source project also means it’s not dependent on its original creators for new features and bug corrections. We may encounter some awesome features in the future suggested or added by the open-source developers community to this new language.

Moreover, Facebook is also working to improve Hack. They did create the language after all. “This is just the first step, and we are dedicated to continuing to evolve this software to make development even easier for both our own engineers and the broader community,” as posted on the Facebook Engineering blog.

What do you think about Hack? Do you think Hack is better than PHP? Can it replace PHP? Please post your answers in the comments.

WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail