r/programming • u/[deleted] • Mar 20 '14
Facebook introduces Hack: a new programming language for HHVM
https://code.facebook.com/posts/264544830379293/hack-a-new-programming-language-for-hhvm/7
173
u/agumonkey Mar 20 '14
Soon we'll feel a great disturbance in the Force, as if millions of type errors suddenly cried out in terror.
136
Mar 20 '14
...and then were suddenly silenced (as lazy developers switched back to PHP).
100
u/desleaunoi Mar 20 '14
"But with the type checking down, I can't even see the errors!"
"Trust your implementation, Luke... Let the PHP flow through you."
2
Mar 21 '14 edited Mar 21 '14
Let the PHP flow through you.
That sounds extremely painful...
→ More replies (1)0
5
u/ggggbabybabybaby Mar 20 '14
Reminds me of when we added static analysis to our build checks. Stubborn developers quickly found a way to keep it quiet.
2
146
u/Xylth Mar 20 '14
The following philosophical objections apply:
[x] The name of your language makes it impossible to find on Google
Taking the wider ecosystem into account, I would like to note that:
[x] You have reinvented PHP better, but that's still no justification1
u/WooParadog Mar 21 '14
Just read through that, best laugh of the day. Thanks man.
5
u/jvwatzman Mar 21 '14
Doubly so since one of the authors now works for us on some stuff tangentially related to Hack :)
1
u/myringotomy Mar 22 '14
Google is very good at figuring out that when I type Ruby or python I mean the language rather than the gem or the snake.
2
u/hairlesscaveman Mar 24 '14
Yes, but the problem here is that you're usually not linking the two terms together with other programming terms. "hack" is often used to get around something done with programming. Might as well call the language "bug" or "code".
→ More replies (1)
163
u/x-skeww Mar 20 '14
"There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors."
"Hack" is a terrible name. It's about as bad as it gets, really. Just imagine searching for anything. Just take your last 10 programming related search queries and replace the language with "hack".
That name is completely ridiculous.
43
u/hrefchef Mar 21 '14
You obviously don't program in rust. You either get rust removal tips, or people talking about the new Rust game that came out.
7
65
Mar 20 '14
Yeah. I thought 'Go' was a bad name until I saw this one. So far, however, nothing beats this for clusterfuckery in naming.
12
u/quindarka Mar 21 '14
I always use "golang" when I search for Go related stuff.
It helps, a little.
2
→ More replies (1)5
9
19
3
u/snowe2010 Mar 20 '14
also terrible because it's already the name of a language used in "Elements of Computing Systems"
2
Mar 27 '14
C++ and C# are also horrible for searches. I remember hearing about the D language. I literally laughed and said "who names a language after a letter... Oh C."
→ More replies (1)2
1
u/neoform3 Mar 22 '14
Is "c" any better?
Type "c string" into google and you'll get underwear.
3
u/x-skeww Mar 22 '14
C appeared in 1972. It's the successor of B. They surely hadn't search engines in mind.
Anyhow, yes, it's still better than "hack". "C" + programming related term will generally yield useful results.
"C string" leads to underwear, because that's a type of thong.
You don't get that kind of ambiguity with other search terms though. E.g. C array will work just fine.
→ More replies (19)1
17
80
u/Error401 Mar 20 '14
I interned at Facebook last summer (and this upcoming summer) and Hack is an absolute pleasure to use compared to vanilla PHP. The code in the Hack portions of the codebase was just orders of magnitude better to read and reason about. So happy this is finally public.
158
u/frycicle Mar 20 '14
absolute pleasure to use compared to vanilla PHP
I don't know it's that much of a compliment.
155
60
u/Error401 Mar 20 '14 edited Mar 20 '14
I guess, to be fair, never programming again in my life is also a pleasure compared to vanilla PHP. That said there was definitely an increase in my sanity when I was writing or reading Hack code compared to older parts of the codebase that still had some scary PHP stuff happening. It felt roughly like C++ or Java, but with more $.
21
u/HotRodLincoln Mar 20 '14
You could use just as many $ in java is you wanted to, or even the full width version $ or hey, if you really hate your maintenance programmer throw a ¢ or _ (_ not an underscore) in there.
51
→ More replies (3)4
2
Mar 21 '14
Next time you find yourself in a vanilla position and want out, don't actually tell anybody. Just leave a short note on your desk before you leave: "Made a million $. Went fishing."
42
u/lickyhippy Mar 20 '14
I get that Facebook has a huge involvement already with a PHP codebase, and I'm grateful for all the work that they do (HipHop, Hack/HHVM), but the fact they basically needed to rewrite the language to not be shit really says something about PHP.
I mean, /r/lolphp/ , just pick anything from there.
9
u/catcradle5 Mar 21 '14
They had to rewrite not only the language (with Hack), but also the entire interpreter (with HHVM).
(To be fair to them, PHP is almost a full subset of Hack though, according to their docs.)
12
6
3
u/leofidus-ger Mar 21 '14
I would say that the fact that PHP is still this popular says a lot about the lack of other languages properly filling PHPs role. For fast, php-style web development, the list of serious competitors is amazingly short.
3
Mar 20 '14
So? Typescript does the same thing to javascript as hack does to php. You don't see people complaining.
11
u/thedeemon Mar 21 '14
There is no shortage of people complaining about JS. And yes, TypeScript does the same thing, shows how bad JS is.
2
u/UloPe Mar 22 '14
The difference is that JS for the most part isn't crush-your-head-on-an-anvil bad
1
1
u/tchaffee Mar 22 '14
They made some small improvements. Most PHP will run under Hack. Haters gonna hate but there are good reasons some of the world's most popular websites run on PHP.
6
u/mirhagk Mar 20 '14
Does it worry anyone else that the code right there uses mysql_query? Isn't this function deprecated, slow, dangerous and warned against?
7
u/Aatch Mar 21 '14
Facebook continued to develop the standard mysql extension long after it was stopped at zend. It's not actually the slow, buggy security hole that the same extension in Zend is. The mysqli extension in HHVM actually just uses the same underlying code as mysql. As does the PDO driver.
→ More replies (1)1
u/Daniel15 Mar 21 '14
Yeah I noticed the same thing and posted about it in the internal announcement to the author of the blog post. A bit of an odd example for sure.
→ More replies (1)
6
10
u/minhaz1 Mar 20 '14
I don't know much about HHVM (or web development) but can I somehow use it with Hack with a LAMP stack? If so, are there any tutorials available?
10
u/Daniel15 Mar 20 '14 edited Mar 20 '14
Yes, you can use HHVM via FastCGI, similar to how you'd use PHP via FPM. This can work with any web server that supports FastCGI (like Nginx, Cherokee, or Apache)
4
u/Error401 Mar 20 '14
http://docs.hhvm.com/manual/en/install.php is a good starting point, along with http://docs.hhvm.com/manual/en/install.hack.bootstrapping.php.
5
u/_-_-_-__- Mar 20 '14
So... can I run a Wordpress/Drupal or some other normal PHP-based CMS install or Framework with HHVM and then develop my own code on top of it in Hack and it will interoperate? Like... can I include a Wordpress file in my Hack code and initialize the Wordpress environment? And the reverse, can I call Hack functions from my PHP Code?
4
u/Daniel15 Mar 21 '14
WordPress can run on HHVM. The Hack and HHVM sites themselves are WordPress sites running on HHVM.
11
u/totes_meta_bot Mar 20 '14
This thread has been linked to from elsewhere on reddit.
I am a bot. Comments? Complaints? Send them to my ^inbox!
18
u/arturosevilla Mar 20 '14
Why don't use a language that already has all of these features, and make a compiler for the HHVM?
50
u/pipocaQuemada Mar 20 '14
Facebook has a lot of php code. Writing a language that's basically php++ means that they can refactor their large codebase over time, and incrementally take advantage of better static guarantees. They don't need to rewrite everything all at once, which would be prohibitively expensive.
Besides, it lets them reuse a lot of the work that goes into compiling php to the HHVM.
→ More replies (2)11
u/matthieum Mar 20 '14
On the other hand, providing you have a modular code base (and if you don't, it's high time to start), then you can migrate modules one at a time... to whatever language you wish.
This ability to let multiple languages/implementations/platforms cohabit is perhaps the most attractive thing about SOA.
→ More replies (6)
4
u/seabrookmx Mar 20 '14
Not to be confused with the Haxe programming language, which is another scrypting language with static typing, except this one is inspired by Actionscript rather than PHP.
The nice thing about Haxe though is that it is multi-target (compiles to C++, Javascript, or bytecode for the very lightweight and fast Neko VM).
Even though I think Haxe is a head and shoulders better language than Hack, Haxe doesn't have very strong commercial backing (ie. doesn't have Facebook behind it) so I doubt it will gain much traction.
1
7
u/GoSailing Mar 20 '14
Oh that looks like a nice step up from using bare PHP. It's basically the same for PHP as Typescript is for Javascript. I definitely like the approach of being as close to a direct superset of the language as possible rather than outright changing all of the syntax like the Coffeescript approach.
6
u/thedeemon Mar 20 '14
This talk answers many questions regarding motivation behind Hack, relationship with HHVM etc.: http://www.infoq.com/interviews/adams-php-facebook
1
3
u/MatrixFrog Mar 21 '14
Lots of hate for the name. But I actually like it. You're building a new language which is intentionally and explicitly the "PHP but better" checkbox from the checklist that always gets posted at these things? Of course it's going to be a hack. But they're admitting it's a hack, in the most conspicuous place possible: The language name itself!
Yes, it'll be hard to Google it, especially at first. If the language catches on, it will become easier over time like it did for Go. I'm not too worried about that.
3
5
u/been0x Mar 20 '14
You mentioned that Hack is suitable for projects of all sizes, but what are the instances where using PHP instead of Hack is preferred, or is Hack a new and improved version of PHP, which it could actually replace?
12
u/Daniel15 Mar 20 '14 edited Mar 20 '14
Hack is a new and improved version of PHP rather than a totally separate language. Almost all existing PHP code is backwards compatible, other than code that uses features that were intentionally removed (like variable variables and the
extract()function). As the blog post mentions, you can convert files one-by-one from "regular" PHP to Hack.
5
u/bimdar Mar 20 '14
I'm quite partial to static typing, so I quite enjoy these static type system bolt-ons like TypeScript and Hack. I mean it wouldn't be something I'd choose to use on new projects but if you have existing code-bases in the languages they're based on then it's the next best thing to completely porting it.
3
u/neoform Mar 20 '14
http://hacklang.org/manual/en/hack.annotations.typejuggling.php
(binary) seems to be no longer allowed, which leads me to the question: are Hack's strings still binary safe? Can I use binary data as the key to a Map?
5
u/dparoski Mar 20 '14
Engineer working on Hack here.
Hack's strings are still binary-safe. HHVM uses the same representation for strings regardless of whether it's running PHP code or Hack code (this is part of our interoperability story). "(binary)" is an alias for "(string)", so you should be able to use "(string)" in your code and everything should work fine.
5
u/argv_minus_one Mar 21 '14
A Band-Aid on top of a mountain of shit isn't going to do anything about the smell. If you want to make a good language, do not use PHP as its basis.
3
Mar 21 '14
Oh god why can't facebook just let PHP die, it's like using the new Ronin 47 movie as a template for your new killer movie.
Nothing good can come from something that toxic.
0
1
u/Mamsaac Mar 21 '14
I remember that no more than 2 months ago I was browsing HHVM's code at Github and I found code like this. I wondered myself "What is this magic?" and searched the web for new PHP features provided by HHVM, but I couldn't find that it was supposed to be the Hack language. So, is it the case? Is all the .php code within HHVM's repository Hack code? And if so, why keep the .php extension?
1
1
1
u/irock168 Mar 21 '14
tonight's story: Government banned facebook because they were encouraging hacking.
1
u/stesch Mar 21 '14
I somebody says to me "But Facebook is written in PHP, too!" I can now say "No. They invented their own programming language and are using it for a year now."
1
u/glacialthinker Mar 21 '14
So two languages implemented in OCaml with nearly the same name: Haxe, and Hack. To add to the confusion, you could have Hack code running on HHVM, and also Haxe targeting php running on it.
1
1
u/GFandango Mar 21 '14
This is what PHP does to you folks.
It's so good after a while you go off to invent your own language.
1
u/tchaffee Mar 22 '14
Yeah because every website out there has a billion active users supported by 3000+ devs pushing to production on a daily basis. Meanwhile Wikipedia and WordPress.com.
1
u/teiman Mar 21 '14
My problem with this is... If I write something based on APC, and theres a huge bug in normal APC, will somebody port the fix to the hack version of APC? or will I have a custom server with rotting modules?
1
u/dparoski Mar 22 '14
HHVM has its own implementation of APC that is completely separate from PHP5's implementation. If you encounter behavioral differences or bugs related to APC when running HHVM, you can report it at our github site (hhvm.com/repo) and we will help get it resolved.
1
1
1
u/bunnyavenger Mar 24 '14
Hmmm... Now I'm thinking they called it Facebook Hack because now If anyone google searches for "hack facebook" they'll get the programming language instead :P GENIUS :D
1
Mar 26 '14
I tried it.
Unless you're starting from stratch, stick to what already works. The configuration is a headache. The guides, when followed, won't work - You have to figure a lot of it out especially when using Apache.
Anyhow: It refused to load http://localhost - That is when I first noticed something was wrong with it. So I started to test it. I was running 2.4.2 version, that's about all that ran correctly.
So then I tried using real existing code. After 10 minutes, it was still loading and nothing was happening. That's when I was lucky.
Many other test-sites and pulls simply loaded blank pages or 404 errors, no matter how I tinkered with the conf file, which it claimed it pointed to (it ignored it).
All in all, I tried to make it work, I even rebooted the computer a dozen of times - after many config changes and attempts - to make sure it wasn't just a mishap (ubuntu isn't error-free). My conclusion right now, is that apt-get remove --purge hhvm is by far the best use of hhvm. Maybe if I change jobs and have to start from scratch I'll give it a shot, it is just not compatible with existing projects.
1
u/TimLim Mar 28 '14
I downloaded the apt-get version. Zero problems. I compiled it myself. No problems.
Don't know what you're running into.
→ More replies (1)
-2
u/Kalium Mar 20 '14
Seems like a decent idea. How's the package system?
I wish Facebook would stop with the "hack", "hackers", and "hacker ethic" stuff. Suffice to say I fundamentally disagree with it for reasons that cut to the core of Facebook's business model.
→ More replies (4)5
u/Error401 Mar 20 '14
There's no package system for native extensions afaik.
And also, I think regardless of Facebook's business model, there is a huge "hacking" culture at Facebook. We have internal hackathons all the time and some of the most popular things on the site started because someone toyed around with it in their spare time.
→ More replies (11)
1
u/celtric Mar 20 '14
Just curious, was it not possible to write each feature as a PHP extension? I'd love to use XHP, type annotations and other great additions from Hack (and have the freedom to choose which features I want), but at the same time I don't want to leave the PHP ecosystem.
1
u/Daniel15 Mar 20 '14
XHP is available separately as a regular PHP extension.
I'm not on the Hack team, but I think it's because Facebook use HHVM so it would have been more work releasing these language features both as PHP extensions in addition to HHVM features. The implementations would be totally different, and changing PHP's lexer/parser to add additional language features isn't trivial. Easier to just focus on the HHVM implementation.
→ More replies (1)
0
u/Chandon Mar 20 '14
Why keep all the ugly from PHP?
Languages like Clojure and Elixir have demonstrated that it's possible to build a language that retains compatibility with an existing language without retaining the syntax or even many of the semantic warts of the original.
→ More replies (3)
297
u/[deleted] Mar 20 '14
I'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.