What about Facebook's newly released Hack language?

Source: Internet
Author: User
Keywords Hack facebook php sullivan bryan
Tags hhvm ruby on rails ocaml
Hack

static types, with some advanced features (in contrast) such as anonymous functions. There are also asynchronous and the like, can not tolerate the variable name or to add $.

> Facebook is a big family that loves PHP, but Hack team leader Blaine Oshaliven (Bryan O ' Sullivan) also points out that, given that many developers are developing many different projects, it will make sense to catch errors before the program runs. This can make the programmer's programming process more efficient, which is just as important as making the program run more efficiently. As a result, some of Facebook's senior engineers have come together to develop the Hack language. Facebook has been using PHP and Hack internally for a year, and is now planning to port the code to Hack as much as possible. O ' Sullivan says that Hack has no real effect on the speed of the code itself ...

New programming language by Via Hack:facebook

Reply content:

Another FB ex-intern jumped out to say a word. The following are personal points of view.
The individual does not think Hack is a separate language. The relationship between Hack and PHP, personally, is much like the relationship between ActionScript and ECMAScript (JavaScript). Despite the introduction of a large number of new elements (type checking, etc.), the fact that it retains PHP's syntax, habits, and standard libraries remains unchanged. Hack more like a dialect (dialect)
Why does Facebook appear to be an independent language in its propaganda? I think the main consideration here is to respect the PHP community and to avoid a lot of PR issues. The compatibility issue left by the first browser war left the internet world scarred, leaving a lesson: No commercial company should be allowed to dominate a standard. So if Facebook releases Hack as a modified version of PHP, it's a concern, fearing that PHP would be the world of Facebook.
The PHP community itself should say it's hard to meet Facebook's needs. The importance of Type Safety I will not say. A very, very important requirement is coroutine. Facebook is an extremely IO heavy application (imagine that every time you open the home page, you need to sort out a feed, get the content of each story, who likes it, the latest comments ...). ), so you need to be asynchronous. The previous Facebook solution was this: Justin Mitchell's answer to Facebook Infrastructure:what is preparables and how is they implemente D? , the code is pretty ugly. And what's the best way to solve an asynchronous code structure? coroutine! Reference A Study on solving callbacks with JavaScript generators 。 PHP 5.5 has finally introduced generators, but Facebook can't wait that long.
But it's clear that Facebook can't move to another language. Because the code is "too old" and "too ugly" to give up existing code and the behavior is naïve. Refer to this article things you should never does, part I 。 The central idea is simple: the programmer who writes the code now is not stupid. Plus a piece is probably smarter than you.
I'd say it would be wise for Zuckerberg to use Php+mysql. Facebook has a history of ten years. Remember what state 2004 is? As Django has just come out, Ruby on Rails will have to wait almost two years. Perl didn't fire from the beginning. ASP is dead, although it is still popular (at least domestically). Besides, PHP is not a good language, but it is very useful to do on the website.
So, the purpose of Hack's existence is not to become a universal language. If you're going to do a new project, consider Python, RoR, and even NodeJS. It exists to solve a very special kind of situation: you don't like PHP but you have to use it. The only thing I can think of is the maintenance of an existing large website. Don't know Wikipedia is interested in not.
Finally, I don't think there is any difference in the nature of any language. Too many people who curse the language forget that the code is written by people. The best language in the three-flow engineers also can not write efficient, easy-to-read, easy to maintain code. Just, some language to the three-flow engineer a self is the illusion of Daniel (Mom I can write Dynamic Web page!). ), which is a big source of PHP notoriety. Why does Haskell sound tall? Because the three-stream engineer has never heard of it. Can't say good or bad, what's the future? At the very least, PHP is an optimization and experience. But the current HHVM to promote it is indeed a bit difficult, installation is not generally complex. Plus, there's a lot of cost if PHP converts to HH. Can only say that the current use of the line, do not expect a large wave of zombies will soon hit.

Turn out to see Hacklang document after writing notes, give you crossing, for reference only:

  • Enhanced input and output types for PHP
      • More rigorous and safe in wording
      • Also supports the nullable type (? Represents a nullable value)
      • Non-transparent type alias (you can assign a type to a new name)
      • Class this pointer type (can point to subclasses when inheriting)
      • Array Type enumeration (specifies the type order in the array)
      • anonymous function type (this is useful for anonymous function parameter conventions)
  • Added type (not explained, all literal)
      • Vector
      • Map
      • Set
      • Pair
      • Shape
      • Tuple
  • Class
      • Input parameters promoted to internal variables
      • Method Distribution: Static dynamic separation (this is too cool, native PHP, you can only write some strange names, Magic way to achieve distribution)
      • Strict class inheritance method overrides (to overwrite the parent class method, you must add a declaration)
  • Alias of Class
      • External extension (=)
      • As syntax (incoming specified x as XXXXXXX)
      • <> Grammar
  • Simplifies Lambda (for example: $x ==> $x * 2)
  • XHP syntax, used to output HTML and XML, to automatically filter XSS (security is hacklang important thing)
  • Trait (strengthened trait)
      • Require inheritance
      • Require implementation
  • Optimized generator and Async (a bit look forward, I actually want Go that way and Channel)
      • Continuas (encapsulates an iterator that specifies the iteration type)
      • Async (declaring asynchronous type functions can execute asynchronously)
      • Awitable (the function representative returning the declaration can be executed with Awit)
  • Discard the features of PHP
      • Global code (does not allow code to be written outside of a function or class)
      • Class name function building method (class function name cannot be the same as class name, or it will be wrong)
      • Calling parent static methods is not allowed (parent::xxxx, you're done)
      • static invocation at the object level (object can only be called by object)
# # Summary

Strict input and output type definitions have been made for PHP, adding several types and more secure HTML syntax. In short, most of the PHP is not rigorous, there are async syntax async, but only stretched. To correct this, the anonymous function was introduced in PHP 5.4 (remember correctly).
UPDATE: Checked, is PHP5.3 support anonymous function and then in PHP5.4 support closure use $this keyword, the impression has always been thought to be PHP5.4 only support.

Hack in FB internal promotion when I just in the internship. I hope the following is not affecting the NDA.

Take a look at the slot and see what Facebook has done on PHP:

According to someone from HN, Facebook had written:a compiler from PHP to C + +; A compiler from PHP to VM byte code; A corresponding runtime for each; Extensions to PHP; A type checker, and an inference engine. Now they has to created a new programming language, which are inspired by PHP.

Lesson Learned:start with a decent programming language.


Why does Facebook have to make a big hack? Is it because the history code base is too big to continue to improve on the basis of PHP itself? The funny thing is that many people put "Facebook in PHP" as PHP is a good language argument ...

In retrospect, hack mainly wanted to solve these problems:
    1. Efficiency
    2. Provide compile-time code checking for large projects
    3. Provides a gradual transition to a new language scenario in the face of a huge existing code base

In order to solve these problems, the corresponding strategy is

    1. Hack is a typed language, which increases the JIT-optimized space of HHVM.
    2. Ditto, hack is a typed language, and comes with type inference provides compile-time code checking

Because of the need to migrate the internal code of FB to hack, a lot of basic things can not be changed. If you remove the variable name before adding $ ... It's better to rewrite the code in other languages, why continue to use hack?

HHVM is the future of PHP ...


Here's some gossip.


    1. Hack this language outside FB discussion is in last year a ocaml of a con (sorry really can't find the original link). Yes, Hack was written in OCaml.
    2. In order to avoid NDA violation, I put a link to http/spyder.wordpress.com/2014/03/16/why-ocaml-why-now/ keyword "web IDE ". This thing doesn't seem to be open source for the time being but it should be fast.
For PHP is a boon, although there are now ruby/py and so on, but PHP in the site development of a long history, a large number of projects still occupy the mainstream. Scala is a Java upgrade, Java itself is upgrading, Hack is also a PHP upgrade it.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.