Slashdot stories can be listened to in audio form via an RSS feed, as read by our own robotic overlord.

 



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:
  • So many bugs (Score:5, Insightful)

    by ClayDowling (629804) on Thursday March 20, 2014 @03:07PM (#46537699) Homepage

    So many of the bugs that have tripped me up over the years would have been solved by simply having static typing.

  • hate the name (Score:5, Insightful)

    by mr_mischief (456295) on Thursday March 20, 2014 @03:07PM (#46537707) Journal

    "Hack" as a language name? Really?

    People are going to explain this at dinner parties. People who kind of understand that programming is more than being good at operating a computer as an end user but don't really know the difference between sysadmin, devops, programmer, business analyst, and DBA let alone what those roles really do are going to ask questions. Those questions will be things like "what kind of programming?", "what technologies do you use?", and "what are you working on right now?" The answer will be something about putting together a quick Hack program to change values in a database, and then it gets awkward.

    Plus, did they consider at all how easily this will get confused with Haxe?

  • by afidel (530433) on Thursday March 20, 2014 @03:10PM (#46537731)

    This sounds a bit like layering design by contract on top of a typically dynamically typed language rather than being a strictly statically typed language. It's an interesting approach and would seem to achieve their goals of faster but more robust development.

  • Nope (Score:5, Insightful)

    by Sarten-X (1102295) on Thursday March 20, 2014 @03:15PM (#46537769) Homepage

    In fact, most PHP files are already valid Hack files.

    No, no, no, and no.

    The single biggest problem with PHP is the tendency for old code and old programmers to keep their bad habits around when moving to new projects. PHP lacked vital modern features (like static typing and namespaces) for so long, and it's evolved so many workarounds (like magic quotes), that programmers have learned the wrong way to accomplish basic tasks. Now they have a new language, supporting the right way to do these things... but the old and broken ways still work. Sure, there will be a few programmers that will use the new way and be thrilled about the good technique, but then time crunches will set in, and code reviews will be rushed (or nonexistent), and those old ways will creep in, bringing the bugs with them.

    Backwards-compatibility with a broken language is a great way to improve a new language's adoption, and a terrible way to build a new language's reputation.

  • Re:So many bugs (Score:3, Insightful)

    by Anonymous Coward on Thursday March 20, 2014 @03:18PM (#46537807)
    Dynamic typing frees your mind to think about the problem at hand and the best solution to that problem, rapidly changing approach and methods as you learn from experience gained. I get sick of spending half my time dicking around with static types, casts, etc and spinning my wheels chasing down type errors when I could be progressing rapidly towards a solution. Unless I'm writing kernel code for a drive by wire system or something similarly life-and-death, I'll take dynamic typing any day and be done twice as fast, moving on to the next challenge. If absolutely necessary, once a final working codebase is established, it can be rewritten to take advantage of the additional lock-down offered by static types.
  • by PhrostyMcByte (589271) <phrosty@gmail.com> on Thursday March 20, 2014 @03:21PM (#46537835) Homepage

    Every few months someone announces a new fad language despite them rarely bringing anything new to the table, or the new things they do bring not being significant enough to warrant switching from some other well-established one.

    I'm actually happy with this one, because it serves an easier to justify purpose: migrating your existing PHP codebase and developers to something that is immediately better and familiar.

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

    by MightyMartian (840721) on Thursday March 20, 2014 @03:25PM (#46537889) Journal

    My interpretation is that they've put a lot of work turning PHP into Java or C. Why go through all this effort when they could simply used one of the C-like strongly typed languages is beyond me. All that effort could have been put into creating a PHP-to-Java converter or something along those lines.

    But hey, it's Mark Zuckerberg's bazillion dollars. If he wants to tape testicles on a eunuch, be my guest.

  • Re:So many bugs (Score:5, Insightful)

    by MightyMartian (840721) on Thursday March 20, 2014 @03:27PM (#46537907) Journal

    It allows you to free your mind, express your inner coding monkey artist.

    And then you get to debug...

  • Re:hate the name (Score:5, Insightful)

    by WillgasM (1646719) on Thursday March 20, 2014 @03:32PM (#46537947) Homepage
    It's actually very clever marketing. Now everybody that searches "facebook hack" will get this as the first result. They get lots of hits for their new language and obfuscate any articles teaching people how to exploit FB accounts. Win-win.
  • Re:English? (Score:3, Insightful)

    by turbidostato (878842) on Thursday March 20, 2014 @05:18PM (#46538801)

    "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. "

    You mean, like any other interpreted languages you could choose?

    "The down-side has always been that the language also had many sloppy characteristics."

    You mean, like those avoided by any other interpreted languages you could choose?

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

    by Chris Graham (942108) on Thursday March 20, 2014 @08:59PM (#46540147) Homepage
    Ah, it seems I started a religious language war simply by sticking up for the tool I (have to) use ;-). I've not claimed PHP is the best language, only it is a comfortable language to me and many others. I just do not feel the pain some developer's always claim to feel, the inconsistencies just don't cause ongoing real world problems for me. I do not lose productivity on a day-to-day basis, they do not cause additional bugs (well, dynamic typing could - and a small number of other things could if you don't have a framework / know the issues), they do not make the code unreadable, and I do not have a problem hiring or training competent developers in the language. Whatever problems there are are easily resolved, and the smallest problem I have as a professional. A PHP developer not aware of the few issues to avoid, would also not have the basic field knowledge to avoid a myriad of other pitfalls that affect all programming languages. I know so many people will read this and think "but there are issues, and you can't excuse that" - I'm not - but I also firmly believe going through your professional career with so much anality for the small niggles doesn't help anybody, and that instead of whinging, people should put their energy into something more productive and positive, like concentrating on client ROI (and no, the 5 minutes you took looking up an inconsistently named function the other day doesn't make an identifiable difference to it), or perhaps, putting in RFCs for cleaning up the issues for PHP6.

    The reason I develop in PHP is because I write consumer software to deploy on web hosts, and I don't chose the web hosts, and PHP is the overwhelming 'standard'. Probably the world would be better if Python replaced PHP, but bitching about the tools people use with arguments that the users of said tools simply cannot relate to, just seems ridiculous, and annoying because it just undermines the good work some seriously talented/hardworking/worthy people are doing. There is absolutely no reason PHP cannot continue to evolve, step by step, without forcing the entire hosting industry to adapt to something else (which is never going to happen).

    I just ported a project from ASP.net to PHP, and my God the problems I saw in that language. Whenever I look at Ruby code, I just see the most inelegant syntax - it just looks like it was deliberately designed to combine being cryptic in some places, with pulling in English words where self-describing layout would be better. And then there are a host of academic languages which have elegant concepts, but poor libraries, or just are too over-complex for real world use.

    For what it's worth, I think the world would be better off if Javascript was replaced too (I get annoyed by that much more than PHP actually, because some basic programming constructs are just hacks, and it is literally impossible to write elegant looking code).
  • Re:English? (Score:4, Insightful)

    by Pseudonym (62607) on Friday March 21, 2014 @01:44AM (#46541153)

    To be fair to Facebook, no other languages had those advantages in 2002-2003. Assuming you didn't want to use F/CGI, plugins for Apache or the equivalent, your server-side scripting options were JSP, Asp.NET and PHP.

    PHP was a reasonable choice under the circumstances, but they've now reached the limit of what it can do. It's good to see that they're moving to an entirely new and better language which just happens to have a similar syntax. If I was a Facebook engineer, I could live with that; syntax matters, but it doesn't matter as much as semantics and pragmatics.

Sentient plasmoids are a gas.

Working...