22 ms·
Hack: a new programming language for HHVM
- devwebee 13y agoIt looks promising, I highly dislike writing PHP and this seems like it might ease the pain, but they could've gotten rid of the damn dollar sign in front of variables, how ugly is this? "return ($y) ==> { return $y + 1; }"
- dparoski 13y agoEngineer working on Hack here. You can actually write you example a bit more concisely in Hack: "$y ==> $y + 1".
- iso8859-1 13y agoReturn statements are optional? So it's just the last statement in a function that'll get returned?
- dparoski 13y agoThe "return" keyword is not needed if the right hand side of the lambda arrow ("==>") is an expression that is not wrapped in curly braces. If the right hand side _is_ wrapped in curly braces then it is treated as a list of statements, in which case you do need to use the "return" keyword.
- dparoski 13y agoEdit: My previous comment was referring to the second occurrence of "return" in your example (after the "==>" arrow). Just noticed I mistakenly dropped the first occurrence of "return"; the first occurrence of "return" in your example is needed.
- rarestblog 13y agoPhpStorm support issue http://youtrack.jetbrains.com/issue/WI-21737 http://youtrack.jetbrains.com/issue/WI-21737
- vezzy-fnord 13y agoLooks like Facebook might have inadvertently turned PHP trendy again. Expect "Why I migrated from Go to Hack" articles soon enough. Either way, the name is very fitting. I have no use for this, but good for Facebook that they've managed to (at least to some extent) evade some of the many PHP pitfalls.
- roberto 13y agoI started web programming using PHP back in 2000, but quickly moved to Python a couple of years later and never looked back. That is, until I joined FB this year as a data engineer. Programming in PHP with Hack/XHP is awesome.
- vineet 13y agoIs Hack an evolution of XHP, or is XHP a subcomponent of Hack?
- dparoski 13y agoEngineer working on Hack here. Historically XHP was developed before Hack. It's available as an add-on for PHP but never became a formal part of the PHP language. When Hack was being designed it needed to work well with XHP (as XHP is used a fair amount with Facebook's code base), so over time it made more sense to start thinking of XHP as being one the language features that Hack offers that is not available in stock PHP.
- copergi 13y ago>Expect "Why I migrated from Go to Hack" articles soon enough Why would you expect that? Obviously the bulk of people migrating to hack will be coming from PHP.
- octo_t 13y agoSee this presentation[1] from Strange Loop 2013 about some design decisions on Hack. [1] - https://github.com/strangeloop/StrangeLoop2013/blob/master/slides/sessions/Adams-TakingPHPSeriously.pdf https://github.com/strangeloop/StrangeLoop2013/blob/master/s...
- bos 13y agoI'm the manager of the team that developed Hack, and I'm sitting here with some of the language designers. Happy to answer your questions.
- Locke1689 13y agoPretty star-studded cast you have on the core team, there. What's your motivation, aside from modernizing Facebook's code base? What language niche does Hack serve which is not served by other languages? Why Facebook at all (aside from the rarity of finding a company to pay you to write a compiler :))?
- bos 13y agoThe sweet spot that Hack hits is that it combines gradual typing (an idea that hasn't yet seen much real-world adoption) with an incredibly fast typechecker. This lets you choose the pace and extent to which you want to adopt the safety of static typing, while preserving your dynamically typed code -- and without sacrificing the rapid turnaround of PHP. That's a unique combination, in my experience.
- Confusion 13y agoHow does your approach compare to Typed Racket and Typed Clojure? Could they conceivably achieve the same performance or is there a fundamental difference?
- webjprgm 13y agoDoes Typed Racket have DrRacket support for instant feedback on errors? (It didn't 4+ years ago when I used Racket.) Typed Racket also includes more types, like ": Integer [more precisely: Negative-Fixnum]" (from docs), as well as polymorphic data structures and higher-order functions. I don't know if this is a "fundamental difference" but it might mean Facebook's type checker can optimize in certain ways that Racket's cannot.
- 13y ago
- habosa 13y agoFacebook is always pushing PHP to new places. Would it be too broad to say PHP is the worst thing that ever happened to Facebook's engineering but Facebook's engineering is the best thing that ever happened to PHP?
- ecaron 13y agoI'd rephrase the question to be "Would Facebook be Facebook without PHP?"
- thescrewdriver 13y agoI don't see why not. It's possible to have done it any any mainstream language.
- nbm 13y agoWhich mainstream language would you have chosen in 2003 that you think would have had similar success?
- maratd 13y ago> Which mainstream language would you have chosen in 2003 that you think would have had similar success? Bingo. In 2003 PHP was the best option to get from zero to hero.
- nobleach 13y agoAs much as I'm not a PHP fan these days, you are completely correct. In 2003, you had CFM (which MySpace actually used at first), Java (and probably some overly complex framework like Jakarta Struts to go with it), CGI, or the new ASP.net. For a college student to do a quick HTML doc with some code interspersed here and there, PHP sounds like the ONLY viable option that didn't have you spending money on licensing, or setting up some huge infrastructure. I used PHP/MySQL too as it was just dead simple for most things.
- 13y ago
- fmitchell0 13y agoVery excited to play with this. While I know many poo-poo PHP, it still is a pretty decent gateway language. If these type of innovations introduce hobby programmers into more professional practices and concepts, I'm all for it.
- VeejayRampay 13y agoWell, it's been poo-pooed for obvious reasons (like Javascript) but those are the languages that are getting all the love in the end, so maybe I should stop programming in a language that I find beautiful (Ruby) and go with the flow. Yes, I'm slightly bitter :/
- ProNoob13 13y agoYou should develop in whatever you love. It's a great thing to know multiple languages, though.
- programminggeek 13y agoI'm really intrigued by the concept of array Shapes. I actually implemented that for Obvious and use it for type checking hashes in ruby with Contracts. https://github.com/RetroMocha/obvious/blob/master/lib/obvious/contract.rb#L176 https://github.com/RetroMocha/obvious/blob/master/lib/obviou... It's cool to see the same idea implemented in Hack. I don't know if anyone at FB has even heard of Obvious, but it's cool that they had the same idea in their language.
- jdp 13y agoWhy a brand new language, instead of building or optimizing the PHP backend for HHVM with an existing language like Haxe? http://haxe.org/ http://haxe.org/
- bos 13y agoIt was very important to us to have a gradual and smooth upgrade path, such that you can start using Hack by just tweaking the "<?php" header at the top of a source file. Obviously switching to a syntactically incompatible programming language would be at odds with that goal.
- jdonaldson 13y agoHaxe is much more structured in how it's organized. It requires an explicit class for code, it has very few methods or variables in the global namespace, it has block-level vs. function-level scoping, etc. Those are pretty typical language features for languages designed for large code bases, but they're probably unfamiliar territory for some php developers.
- vanilla 13y agoNaming a language hack ... very poor choice. Searching for Go, C, C++ is already bad, now you can add hack to the list.
- VeejayRampay 13y agoHacklang. There, just like go, problem solved.
- vanilla 13y agojust gone though the slides of a Hack Talk (https://raw.github.com/strangeloop/StrangeLoop2013/master/slides/sessions/Adams-TakingPHPSeriously.pdf https://raw.github.com/strangeloop/StrangeLoop2013/master/sl...) > • [ X ] The name of your language makes it impossible to find on Google” appending "-lang" certainly gives you better results but still does not find you a lot of un-tagged good blog posts
- psychometry 13y agoThat would only solve the problem if everyone referred to it as "Hacklang", which will surely not be the case.
- checker659 13y agoI'm not sure what to think of the language (other than the fact that it looks very similar to Typescript); but, as for your comment, suffix the word lang and you're golden : golang, dartlang, hacklang.
- Dale1 13y agoI know, i went to look for info on "facebook hack" because we want to use it in work. You can imagine what came up!
- mlubin 13y ago"Hack provides instantaneous type checking via a local server that watches the filesystem." What does this mean?
- bos 13y agoOn Linux, we use the inotify subsystem to be informed every time you save a source file or switch branches. The hh_server process can then update its data structures immediately, without being explicitly asked.
- wink 13y agoI don't really get why this is the second paragraph on the page of a language though. It's like touting the jar command in an overview of Java.
- bos 13y agoBecause this is tremendously important to the usability of the language. One of the reasons that PHP has been such a success is that you can simply save a source file and reload a web page to see what's going on. The server-based typechecker that runs instantaneously is what makes it possible for Hack to replicate this experience: you save a file and reload a web page, but you have the safety net of a typechecker that told you about your type errors as soon as you saved the file. I can't overstate how important this instant feedback is: it's really the thing that distinguishes Hack from working in a more traditional compile-based static language.
- amenghra 13y agoThe fact that we wanted the type system to be instantaneous drove some of our design decisions.
- acorkery 13y agoWas it debated whether this should be a tooling feature - thinking of an IDE plugin that parses and type-checks in the background rather than a dedicated service to watch text files on disk
- cab_codespring 13y agoOdd, just two days ago I was remembering a college class where we had to create a new programming language, and I named mine "Hack". The cover of the paper was a copy of K&R only "C" was replaced by "Hack" and of course I was the author.
- amaks 13y agoHack to PHP is as Dart to JavaScript.
- reikonomusha 13y agoI am baffled as to why you'd build your castle atop a crumbling foundation. I have wondered why FB didn't use a proper language with proper typing to begin with. I mean, I "understand" logistically: they already had a giant codebase in PHP, migrating a codebase is expensive, and it's difficult to hire and train 1000s of hackers in e.g., OCaml. (They do have some OCaml people, but they are outliers. OCaml was my favorite thing to write there, though it didn't afford some of the same niceties and interactivity as the PHP code they had, only because the support was down by several orders of magnitude.) But at the same time, layering FP with a home rolled static type checking server (??) is bug prone and is certainly yak shaving (which they have time and money to do). Now they've written (1) a compiler to C++, (2) a compiler to VM byte code, (3) a corresponding runtime for each, (4) extensions to PHP, (5) a type checker, and (6) an inference engine. That's a lot of stuff. And in the end, it's still PHP, which is duly disliked. (Though Facebookers don't seem to care. The prevalent attitude toward it is that "PHP, as it's coded here, is mostly like C++, and that's OK.") Writing correct type checkers and inference engines is kind of difficult. They seemed to take the approach of just building onto it incrementally until it just seems to work. That approach led to many bugs in many cases that just simply aren't thought of when one is trying to build inference engines by hand, as opposed according to theory. Type checking and inference is an area ripe with theory and attached formal, mathematical semantics. Standard ML's standard is perhaps the most infamous; it's a collection of mathematical statements about the language. That way, the compiler is now almost an engine to prove your code is correct. I don't see how the same guarantee can be made with something that is just cobbled together.
- itafroma 13y ago> I am baffled as to why you'd build your castle atop a crumbling foundation. > I have wondered why FB didn't use a proper language with proper typing to begin with. I would suggest watching Keith Adams's talk, "Taking PHP Seriously": http://www.infoq.com/presentations/php-history http://www.infoq.com/presentations/php-history He goes through why Facebook uses PHP and decided to build upon it to create Hack. I highly recommend watching the whole thing, but the main three things he points to are: 1. Frictionless programmer workflow with a short feedback cycle 2. All PHP requests start out with the same consistent state by default 3. Rigid style of concurrency
- aleem 13y agoI wish these extensions came by way of the PHP core rather than a language that is superimposed on PHP. However, this is awesome. Is this a layer that is superimposed on PHP that falls back to the default interpreter for unimplemented features or is this a fresh implementation. I suppose my question is, how reliable is this. Are the core PHP bugs going to manifest here? If a bug gets fixed on core PHP, will hack be lagging behind?
- camus2 13y ago> I wish these extensions came by way of the PHP core Well where is PHP core then? to my knowledge while PHP 5 was a huge step forward, PHP core did little to fix PHP stupid design flaws,for the sake of backward compatibility. We are in a new era, libraries are more and more decoupled,so they are easy to write or rewrite,backward compatibily shouldnt be an issue when libraries are well versioned and tested across different versions. And Wordpress folks dont care about PHP.next.Why bother with them?
- copergi 13y ago>I wish these extensions came by way of the PHP core rather than a language that is superimposed on PHP Someone has to do it, and the PHP developers have proven time and again that they aren't going to. At some point the only options are to leave PHP altogether, or make your own PHP that sucks less.
- wambotron 13y agoI haven't looked this over too much but I'm curious as to why they did this: <?hh class MyClass { const int MyConst = 0; private string $x = ''; public function increment(int $x): int { $y = $x + 1; return $y; } } instead of this: <?hh class MyClass { const MyConst: int = 0; private $x: string = ''; public function increment(int $x): int { $y = $x + 1; return $y; } } The first seems inconsistent to me. Especially coming from AS3/Haxe where the function return value is indicated in the same manner.
- jdp 13y agoWould be more consistent to suffix the types in function decls as well, e.g. `increment($x: int)` vs. `increment(int $x)`.
- wambotron 13y agoYep. So much weirdness here when they had a really good shot at "fixing" it.
- elgenie 13y ago(I work on Hack at FB) function f(int $x): float { ... } For property and constant declarations, we chose to be consistent with the parameter typehint syntax (int $x) instead of the function return type annotation (float). A nice effect of this decision is that this allows us to change: class C { private int $x = 20; public function __construct(int $x,) { $this->x = $x; } } into the shorter and cleaner: class C { public function __construct( private int $x = 20, ) {} }
- mogui 13y agoIt seems like a strange monster with PHP body and C++ head or the other way around you choose
- amenghra 13y agoYes, pieces of Hack will feel similar to other languages. bos said in another thread: "Yep, we're happy to be inspired by good ideas when they're obviously the right path to walk."
- paulyg 13y agoAre there any plans for a Hack -> PHP transpiler? Or is that impossible? It would be nice to develop on Hack, transpile back to vanilla PHP where we still have to use the PHP.net runtime (shared hosts, Google app engine, Engine Yard, etc)
- amenghra 13y agoHack is more than just a type system. At the type level, it would be trivial to erase the types and run the code on vanilla PHP. Dealing with everything else is much harder (xhp, containers, lambda, etc.), at which point it just makes more sense to use HHVM.
- Touche 13y agoThis rubs me the wrong way. > 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. In which way does it offer the benefits of dynamic typing? The entire point seems to be to abandon dynamic typing, which is fine, but not what that sentence says. I'm guessing, for example, you can't really do meta-programming with Hack in the way you can with dynamic languages, is that correct?
- bos 13y agoIt's more accurate to say that the point is to let you use dynamic typing where that makes sense, and static typing in the many cases where it helps. Hence "best of both".
- camus2 13y agoAFAIK large PHP libraries(Doctrine/Symfony) generate PHP code (from config files for instance) that is then required and executed. You cant be more meta than that. I dont know if you can do that with Hack, but that's definetly a big PHP pattern.
- jwatzman 13y agoIt depends on what you mean by "with Hack". You cannot do this in Hack code -- we disallow the dynamic features of the language you need to do this; they are impossible to statically typecheck and verify. However, Hack code iteroperates seamlessly with PHP code, so there's nothing stopping you from having some PHP files in your codebase that do anything that standard PHP can do.
- lerdorfsghosts 13y agoIf hack is the solution, you're asking the wrong question!
- jtreminio 13y agoIf you want to try out Hack (and HHVM) quickly, my FOSS project lets you quickly set up a VM using Vagrant and Puppet: https://puphpet.com https://puphpet.com
- gaoshan 13y agoPuPHPet is great for getting a ready to go VM with a PHP and all the trimmings. Super easy, super fast.
- wes-exp 13y agoSounds like they added optional type declarations, lambda expressions, and a few more goodies to PHP. I am reminded of http://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule http://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule. Facebook is now at sufficient scale where they are reimplementing Common Lisp on top of PHP.
- inglor 13y agoAm I the only one who finds it ironic they have the old deprecated `mysql_*` API in the sample?
- TazeTSchnitzel 13y agoOh great. Now when PHP expands its type annotations, they'll be incompatible with Hack. :(
- zmanian 13y agoProvides some context on the language development. http://www.wired.com/wiredenterprise/2014/03/facebook-hack/ http://www.wired.com/wiredenterprise/2014/03/facebook-hack/
- treblig 13y agoMan, it's going to be really hard to search the Internet to troubleshoot this. Search: "Hack Anonymous Function" Search: "Hack Background Process"
- psychometry 13y agoAs a frequent user of R, this is one of my biggest pet peeves. There are a practically infinite number of unique, interesting, pronounceable, google-able names for a new programming language, yet we continue to get stuck with this shit.
- nobleach 13y agoA few months ago, "Martini" came out for "Go". I love the framework, but man, searching for stuff on Google was a PITA.
- jamieomatthews 13y agoAt least go says in their official docs, when posting/searching for the language, use "Golang"
- randartie 13y ago"php hack anonymous function"
- elwell 13y agoI thought Hack was already released months ago?
- elwell 13y agoSomewhat unrelated, but curious: Does anyone know if Facebook still uses MySQL heavily?
- HarrisonFisk 13y agoYes, we are still very active users of MySQL. Most of the primary portions of facebook.com are still served from a backend MySQL system (with lots of caching and many other services involved). Some data is not stored in MySQL, but in other systems such as HBase (messages being a big one).
- mh- 13y agohttps://www.facebook.com/MySQLatFacebook https://www.facebook.com/MySQLatFacebook
- nick2021 13y agoPHP is a joke.
- kackontent 13y agoThis is great and exactly what I need in my PHP. Glad to see types making sort of a come back (see also: TypeScript) as I think they're, in one way or another, necessity in a large scale applications. One note though - the success of this depends on the success of HHVM. Hopefully FB guys understand that and will push even more to make HHVM the best platform to have for running PHP on.
- Crito 13y agoDoes anybody know if Hack can correctly parse integer literals, properly rejecting malformed ones? PHP cannot, so I wonder how deep the relationship goes.
- cpeterso 13y agoIs Facebook's code so monolithic that they can't deploy new, decoupled services written in new languages? Twitter did this with Ruby, Java, and Scala. Didn't Facebook create Thrift RFC for exactly this purpose??
- nbm 13y agoFacebook already has several decoupled services written in other languages. The PHP codebase is mostly the front-end code which, beyond some database work, dispatches heavy lifting to back-end services written in C++, Java, and other languages. As you say, Thrift connects this all. You can look into our C++ core library, Folly, and other C++, C, Python, and Java applications and libraries like Rocksdb, Presto, watchman, Buck, flint, scribe, and so forth on github.
- thatmiddleway 13y agoLooks like another way to polish the PHP turd.
- dghf 13y ago"You have reinvented PHP better, but that's still no justification": http://colinm.org/language_checklist.html http://colinm.org/language_checklist.html
- georgebarnett 13y agoMy favourite comments are the ones where some random geeks tell the guys who have built a multi-billion dollar business with hundreds of millions of daily active users how they're doing it wrong. Congrats to Facebook on taking PHP forward. It powers a vast amount of the web and it's great to see that it's getting some engineering love!
- tszming 13y ago>> where some random geeks tell the guys who have built a multi-billion dollar business with hundreds of millions of daily active users how they're doing it wrong. Remind me the words from Steve Jobs: "By the way, what have you done that’s so great? Do you create anything, or just criticize others work and belittle their motivations?"
- bsaul 13y agoI'm really curious to know if any new project will start using this language. I really wouldn't understand why they would. I think that would be an argument to explain why some consider this whole project a loss of time in the long run ( although probably something really great from a purely CS pov) Edit : i just forgot that i still haven't found any server side language i'm satisfied with. I'm still waiting for a type-annotated variant of python to catch on.... So maybe hack would be a good choice after all. It's such a pity they started this work based on php rather than any other cleaner language.
- msie 13y agoWanted: Backend developer. Must have 5 years of experience with Hack.
- yulaow 13y agoAs said on reddit, that is really a poor choice of name. Good luck looking something related to this language on google putting "hack" in the searchbox... It is even worse than "Go"
- varkson 13y agoI imagine everyone is going to start calling it hacklang.
- z3phyr 13y agoThey have best functional programming language geeks around and they made this?
- pjscott 13y agoI realize it must be shocking to see functional programming language geeks solving real-world problems in a pragmatic way. :-) Seriously, though, they wanted to move a large PHP codebase over to a better language, at the scale of a multi-billion-dollar tech company, in a reasonable amount of time. They accomplished this. What's the criticism here?
- z3phyr 13y agoI am actually impressed. What shocked me was, functional programming technomancers are not like that at all!
- evincarofautumn 13y agoThe best functional programming language geeks generally know what they are doing; that is precisely why they made this.
- bowlofpetunias 13y agoEvery negativity thread on PHP on HN just serves as a reminder how poorly informed and inexperienced most developers here really are. Good to keep in mind the next time you read a topic on how awesome language X/framework Y/method Z is. It's depressing to see how much of our profession is informed by the desire to being cool and fashionable, like kids in schoolyard.
- thinkindie 13y agoeveryone has it's own <opinion> over the fact that facebook had to use another language rather than php. On the other side there is the fact that facebook managed to get one of the most visited website on top of php, period. This is a <fact> and we would never know what would be facebook if it was built on top of another language. Probably they had to shut down early just because they were not able to hire enough developers to keep pace with new stuff and scale. At the same time they haven't suffered the same amount of issues twitter had to deal with (remember the landing whale?) with much less users and traffic just because they were using RoR and that lead them to move to something completely different with scala and a different architecture. But still, facebook has about 4x times users and much more data to deal with (more text, images, video and so on). Nevertheless, let's remember that web applications are not a one-shop monolithic anymore.
- lukashed 13y agoOff topic: Can anyone else see a trend to name projects so that they're impossible to google? Hack, Go, Celery, Fig, Cucumber, Lettuce, you name it. E.g. the only way how I could find useful resources on how to run celery with fig was to exclude -gorgonzola.
- jlebar 13y agoSo argue. Much armchair quarterback. Very flame. Wow. It's entirely appropriate and reasonable to say "I don't understand why Facebook would do this; please explain it to me." But it reflects a supreme lack of humility to say "I don't understand why Facebook would do this; they must be idiots, and when they, armed with inside information I don't even know I don't have, come to defend themselves, I will angrily try to convince them of the error of their ways." If you think what Facebook has done here is stupid, why is that something to get upset over? In fact, why is it even something worth arguing about? You're not going to convince anyone who matters, and anyway you have nothing to gain by doing so: Instead, just short Facebook stock and be smug in the knowledge that, when Facebook announces next year that they're abandoning PHP in favor of a ménage à trois of OCaml, F#, and Clojure, you'll be able to say "I told you so".
- cpayne624 13y agoWish I could upvote this a bunch of times
- nness 13y ago> PHP only supports a 256-character set, and hence does not offer native Unicode support :( This was their opportunity to to get multi-byte strings right...
- sesm 13y agoIt's good to see gradual typing rising! 2 things are not obvious from the article: 1. Why a new language, and not just a gradual typing tool for PHP (like Typed Racket and Typed Clojure)? 2. Is type information somehow passed to runtime to assist JIT compilation?
- srg0 13y agoAny¹ sufficiently advanced social network contains an ad-hoc, statically typed² implementation of half of PHP. ¹ YMMV ² sometimes See also: KPHP (subset of PHP to C++ translator, released by Vkontankte).
- argimenes 13y agoI don't understand why there is so much fuss about PHP in 2014. Hasn't most serious web development moved beyond scripting languages? Java and C# have been mature languages for statically-typed web development for years and are not difficult to achieve competence in. And for more fluid yet terse server-side languages you could always go with Ruby, or Smalltalk, or Racket, or F#, and their associated frameworks. Defending PHP in 2014 is almost as surreal as defending Classic ASP in 2014.
- islon 13y agoIt seems like the name really suits the language.
- himelnagrana 13y agoFirstly, Awesome! Need to traverse more in it - definitely. But as the documentation says primarily "HHVM can run both your PHP and Hack code, either separately or when both are part of one project." -- does that means we can imagine a framework or something like that - where parts of it is in Hacklang and parts are in old PHP? or such project is somewhere there already?