Forgot your password?
typodupeerror
PHP Facebook Programming

Facebook Introduces Hack: Statically Typed PHP 230

Posted by Unknown Lamer
from the sml-and-php-fall-in-love dept.
alokmenghrajani (2602135) writes with news of Facebook's new Open Source language, Hack. Quoting: "Today we're releasing Hack, a programming language we developed for HHVM that interoperates seamlessly with PHP. Hack reconciles the fast development cycle of PHP with the discipline provided by static typing, while adding many features commonly found in other modern programming languages. ... Traditionally, dynamically typed languages allow for rapid development but sacrifice the ability to catch errors early and introspect code quickly, particularly on larger codebases. Conversely, statically typed languages provide more of a safety net, but often at the cost of quick iteration. We believed there had to be a sweet spot. ... Hack has deep roots in PHP. In fact, most PHP files are already valid Hack files. ... Our principal addition is static typing. We have developed a system to annotate function signatures and class members with type information; our type checking algorithm infers the rest. Type checking is incremental, such that even within a single file some code can be converted to Hack while the rest remains dynamically typed. ... If a function parameter or class member does not have an explicit type annotation, the type checker considers its type to be dynamic, and it does not check the type of that value." In addition to static typing, they've introduced proper closures that capture the lexical environment, generics, collections, and array shapes. The Hack website has more details. There's a fairly complete language manual, tools to infer types in PHP source and annotate the code, and source available under the PHP license.
This discussion has been archived. No new comments can be posted.

Facebook Introduces Hack: Statically Typed PHP

Comments Filter:
  • Re:English? (Score:2, Informative)

    by Anonymous Coward on Thursday March 20, 2014 @04:02PM (#46537663)

    FaceBook is developing an in-house version of PHP that adds optional static typing and some other features.

  • by ArcadeMan (2766669) on Thursday March 20, 2014 @04:18PM (#46537805)

    Ever tried to access 8-bit byte arrays and write them to a binary file in PHP? It's hell and it takes a lot of work to go around all the stupid dynamic typing.

  • by Anonymous Coward on Thursday March 20, 2014 @04:29PM (#46537927)

    Let me introduce you to https://en.wikipedia.org/wiki/Cython

    You are welcome.

  • Re:English? (Score:5, Informative)

    by Chris Graham (942108) on Thursday March 20, 2014 @05:09PM (#46538261) Homepage
    For pragmatic-minded people, PHP is an extremely productive language to work in. No compiling, or waiting for compiling, no object files to mess with or get out of sync, and still relatively good speed. It really removes a lot of inconvenience between the programmer writing code and testing it. Despite what the detractors say, I've always found it a joy to work in (and I have worked in many languages).

    The down-side has always been that the language also had many sloppy characteristics. Modern PHP has cleaned up a lot of the language design errors, and static typing is extremely useful for reducing quantity of bugs (I know this as I developed a PHP fork that enforces this and it's saved me many many times over the years). HHVM adds much more speed, so that really complex modern social webapps are really needing. There are still many small inconsistencies in the language, but it's not a big deal given the other advantages.
  • Re:English? (Score:5, Informative)

    by Pseudonym (62607) on Friday March 21, 2014 @02:34AM (#46541115)

    No. Facebook is developing a new language which is syntactically similar to, and inter-operates with, PHP. Calling Hack a "version of PHP" is like calling Delphi a "version of ALGOL".

I have not yet begun to byte!

Working...