Facebook's Hack programming language builds code safety into PHP
Hack pairs PHP's ease with the safety controls of older languages
IDG News Service - Facebook has released a programming language called Hack, which marries the ease of PHP with the rigorous safety controls of older languages such as C++.
PHP programmers should easily understand Hack, which replicates many of the same features and functions of PHP, and adds a few of its own for greater productivity, said Bryan O'Sullivan, a Facebook engineer on the project.
Over the past year, Facebook has converted nearly all of its PHP code base to Hack, which makes up the core of its website.
Both projects set out to strengthen a popular dynamic programming language so it can be more easily used by large software teams to design mission-critical applications.
Individuals would also benefit by using Hack, O'Sullivan said, both in terms of increasing performance of their websites and improving the overall quality of their code.
Hack requires Facebook's HHVM (Hip Hop Virtual Machine) to run. HHVM is a virtual machine that compiles PHP, normally an interpreted language, into byte code, so it can run more quickly.
Hack is basically an extension of the PHP language with built-in static typing, a feature found in more traditional programming languages such as C/C++ and Java, O'Sullivan said.
With dynamic typing, "there is no explicit information in the source code that describes what kind of information the program is dealing with," O'Sullivan said.
In contrast, static typing requires the programmer to define the data type for each variable before that program is compiled or run.
Though it takes extra work to implement, static typing prevents run-time errors occurring when the wrong data type is entered into the program, either by human input or some other computer function.
"There are certain kinds of errors and crashes that can occur," if the programmer is not careful about what data is assigned to variables, O'Sullivan said. "These latent errors can hide for a long time in a dynamically typed languages."
The HHVM virtual machine has a built-in type checker to ensure that all of the typed information is correct. Hack even allows the programmer to define unique data types.
"Syntactically, Hack is very close to PHP. We allowed it to be possible to run PHP and Hack code side-by-side so you can gradually convert your language codebase from PHP to Hack," O'Sullivan said.
Certain deprecated PHP features, however, are not supported in Hack, and neither are a handful of features that don't work well with static typing.
- DevOps meets ALM in the Cloud - Cloud DevOps PaaS To improve software delivery performance and effectiveness, teams need automation, governance, architecture best practices, and increased team collaboration. Find out more.
- Coding with JRebel: Java Forever Changed With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with...
- What Developers Want: The End of Application Redeploys Eliminate application restarts in Java with JRebel! JRebel is a JVM plugin that eliminates application redeploys from the Java development cycle, a process...
- How a German energy company saved 1 day per week of development time with JRebel Check out the following case study to see how Heliocentris, a global energy supply and efficiency company deployed a development solution that was...
- It's not too late...Get Your Mobile Questions Answered Live! How can IT provide seamless and secure mobile communications and collaboration for all? Join this live Webcast as IDG asks an expert panel...
- Why do you need an enterprise mobile platform? Today companies must offer great apps that run on a range of devices, and connect to an exploding set of backend data. Appcelerator... All App Development White Papers | Webcasts