r/programming • • 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/
802 Upvotes

526 comments sorted by

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.

37

u/[deleted] Mar 20 '14

Why aren't you working on haskell? ;)

70

u/[deleted] Mar 20 '14

What makes you think that I don't do that, too? :-)

→ More replies (5)

18

u/tending Mar 20 '14

Can the JIT use Hack's static typing to generate faster code?

30

u/[deleted] Mar 20 '14 edited Mar 20 '14

It can, and that's something we hope to do quite extensively, but we're just beginning that journey.

6

u/LightShadow Mar 20 '14

What's the expected support/lifespan of this project? Is the Hack team going to be working on Hack exclusively, or is this something that has a foreseeable stopping point?

26

u/[deleted] Mar 20 '14

“It's tough to make predictions, especially about the future.”

We expect to be investing in Hack, PHP, and HHVM for a long time to come. Every piece of work we do in this realm pays itself off manyfold; that's one of the pleasures of working on a core technology.

→ More replies (1)

84

u/detroitmatt Mar 20 '14

If I'm not already using PHP, why should I use Hack?

86

u/jvwatzman Mar 20 '14

Engineer working on Hack here.

For as much flak as PHP gets, there are actually a lot of good things about the language. The fast development cycle -- edit php script, refresh -- is something amazing that you don't get in a lot of statically typed languages, which usually have a compilation step. The crazy dynamic things you can do also occasionally have their place, though it's certainly easy to shoot yourself in the foot.

On the other hand, a lot of the time you want the safety that strong static typing can give you. Even just the null propagation checking can immediately find tons and tons of silly little bugs without even running the code, and ensure that the code stays consistent as a "mini unit test" if you will.

Hack hits the sweet spot of both. Wiring the Hack typechecker into vim was really revolutionary for me -- having both the immediate feedback of the type system for all the silly bugs that I was writing, along with the fast reload/test cycle from PHP, is great.

→ More replies (70)
→ More replies (12)

177

u/expertunderachiever Mar 20 '14

Couldn't you name it php++ like it should have been called? :-)

172

u/alokmenghrajani Mar 20 '14

The PHP license would not allow it: "4. Products derived from this software may not be called "PHP", nor may "PHP" appear in their name[...]"

286

u/expertunderachiever Mar 20 '14

just put the name backwards then.

→ More replies (9)

32

u/[deleted] Mar 20 '14

GNP:

GNP's Not PHP.

→ More replies (1)

35

u/Vulpyne Mar 20 '14

I wonder if they could have called it QIQ.

→ More replies (13)
→ More replies (18)

57

u/max_t2 Mar 20 '14

yeah "Hack" is a weird name for a programming language...

→ More replies (57)
→ More replies (4)

36

u/jellofiend84 Mar 20 '14

I think more thought should be put into names, especially programming languages that if they become popular will be googled a bunch. Hack maybe a great language but I imagine it would be a pain to work with when you run into an issue and want to google: hack <programming problem> example Even if hack becomes the #1 language I doubt that will return useful information. Google is probably my most important development tool and you've completely neutered it.

20

u/christophermoll Mar 20 '14 edited Mar 21 '14

I usually don't take issue with programming language* names, since it didn't hurt Java, Ruby, Python, or other languages with names that are real words. But I can definitely see "Hack" being a problem, since it's not just already a word, but a word already associated with programming. Even limiting your search to SO or another specific site won't eliminate extraneous results.

14

u/[deleted] Mar 21 '14

Have you ever tried to learn R? Ugh...

→ More replies (1)
→ More replies (1)
→ More replies (1)

22

u/snowe2010 Mar 20 '14

Why did you use the name Hack, which is already a programming language used in Elements of Computing Systems by Nisan and Shocken?

31

u/mk270 Mar 20 '14

Cheers.

The writeup linked above says it's in OCaml ("Hack is written primarily in OCaml. "), but github has it mainly in C++ at https://github.com/facebook/hhvm .

Are there two implementations, or is there some part (e.g., compiler) written in OCaml as part of a larger system?

37

u/shaver Mar 20 '14

While HHVM in the large is mostly C++, the Hack portions themselves are mostly in OCaml: https://github.com/facebook/hhvm/tree/master/hphp/hack/src

→ More replies (1)

20

u/technofiend Mar 20 '14

Could you host a page somewhere besides facebook? This may come as a surprise, but facebook is considered non-essential for work and is blocked at a ton of places.

Still I'd like to read all about it and maybe benefit from your team's work. So maybe a github page or something?

11

u/Nomikos Mar 20 '14 edited Mar 20 '14

http://hacklang.org/
Oh alright, Google cache of this posts link.

14

u/rydan Mar 20 '14

hacklang would have been a better name.

16

u/rydan Mar 20 '14 edited Mar 21 '14

Why "Hack"? Do you know how messed up this is going to make Google search?

For instance if I want to find something about how to integrate with wordpress I'm either going to get a bunch of results on how to hack wordpress, end up on some FBI list, or when I want to actually hack wordpress I won't be able to find out any information.

Edit: I forgot a real world example. Today I wanted to see if today was the first day of Spring so I searched for "Spring" in Google and the first page was nothing but Java frameworks.

15

u/[deleted] Mar 21 '14

I expect people will use "hacklang" in much the same way that "golang" is used.

6

u/EnergyCritic Mar 21 '14 edited Mar 21 '14

Seconded. Can we quit with the colloquial-word name scheming for programming languages?

I find it confusing that OP is appropriating the term "hack" which already has a very specific meaning in programming culture.

While many may not agree, the best named language in the business is Perl. Nothing else out there uses this term. No one is going to mistake it for anything else.

4

u/jb2386 Mar 21 '14

My feeling is that if they can SEO it properly it drowns out the other "Hack Facebook" searches.

→ More replies (2)

9

u/[deleted] Mar 20 '14

Do you personally believe that investing so much resources in a 'safer PHP' is the right business decision for facebook? This is a genuine question. And can you elaborate on your thinking and that of your bosses?

I ask because it seems like it would be possible to use some other existing language and simply build some nicer tooling / infrastructure to work for Facebook's particular needs. Did you and/or your managers consider this, and if so, why was this path rejected?

I am sure you guys have your reasons, so I am genuinely asking here, not just playing devil's advocate.

12

u/[deleted] Mar 20 '14 edited Mar 20 '14

As someone who no longer does much PHP and (nothing personal) avoids Facebook... what's the relevance and potential use of Hack for someone like me?

Edit: Please read below to understand the full context of the question before downvoting.

→ More replies (13)

2

u/[deleted] Mar 21 '14

This has probably been asked but why did you go for that format?

It seems to me it would have been better to go with a more standardized approach like

int function doSomething(){

2

u/Disgruntled__Goat Mar 21 '14

On the off chance you're still replying to comments...

Do you have plans to clean up the standard PHP library in Hack, or introduce string objects?

2

u/leofidus-ger Mar 21 '14

Is there some tool to convert Hack back to regular php? I think for many people it would be easier to start out by developing in Hack while still deploying in existing php setups.

→ More replies (2)

2

u/[deleted] Mar 21 '14

Why do types for method definitions come after, while types for variables come before?

2

u/C_Hitchens_Ghost Mar 21 '14

How intoxicated was the team when they finally settled on the name "Hack?" Why did "Rig" "Slack" "LazC" not make the cut?

2

u/siamthailand Mar 22 '14

Please tell me you aren't the retard who named this language. Please.

3

u/krues8dr Mar 20 '14

Any IDE support yet? Sublime Text syntax at least?

6

u/gclaudiu Mar 21 '14

There's support for emacs and vim. Feel free to send a PR on GitHub for Sublime Text, you can just call the typechecker with hh_client --json and get back a JSON with all the errors :)

→ More replies (1)
→ More replies (2)

4

u/YoYoDingDongYo Mar 20 '14

I'm curious why you decided to fork the language rather than try to get the new features in Hack integrated into PHP?

17

u/[deleted] Mar 20 '14

Because there is no way they would have been accepted?

→ More replies (1)

14

u/bkv Mar 20 '14

It's not a fork, it's a new language that runs on the same VM. Also, the time to get new features implemented into an existing language takes a long time, if the maintainers even accept them in the first place.

→ More replies (4)

13

u/[deleted] Mar 20 '14

It's likely because the Internals list is rife with politics and pissing contests. Also, this fits their business needs, while dealing with the PHP Internals developers would be time consuming. Now that it's open sourced, there's the possibility of Internals developers pulling in some or all of the changes.

8

u/James20k Mar 20 '14

I don't think static typing will get integrated into php

→ More replies (8)

0

u/[deleted] Mar 20 '14

[deleted]

49

u/[deleted] Mar 20 '14

These are brilliant suggestions. If we hire you, can you please plan to have them all completed by the end of Q3?

19

u/Error401 Mar 20 '14

spend a year rewriting Facebook

What could possibly go wrong?

→ More replies (3)

4

u/gordonkristan Mar 20 '14

Static typing is not the only improvement that they made with Hack. And even if it was, given the potential performance benefits, I would say that it is worth it to add static type-checking to a language.

4

u/thedeemon Mar 20 '14

They've got millions of lines of code there. Rewriting is not an option.

→ More replies (1)
→ More replies (42)

7

u/brownmatt Mar 21 '14

In the acknowledgement section, is that the Erik Meijer?

15

u/[deleted] Mar 21 '14

Yes; we have rather a good team.

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

u/[deleted] 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."

→ More replies (9)

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.

→ More replies (1)

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 justification

http://colinm.org/language_checklist.html

→ More replies (5)

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

u/Aatch Mar 21 '14

Or the type of fungus. That's less common of a result though.

65

u/[deleted] 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.

→ More replies (1)

5

u/MrPopinjay Mar 21 '14

That's amazing.

→ More replies (1)

9

u/I_Write_Good Mar 21 '14

I thought processing was pretty rough!

19

u/AsletPT Mar 20 '14

You'd have to type hacklang not just hack...

3

u/snowe2010 Mar 20 '14

also terrible because it's already the name of a language used in "Elements of Computing Systems"

2

u/[deleted] 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

u/Denommus Mar 20 '14

Like all those languages with terrible and hard to search names that were notorious failures, like C, C++, C#, Java, Lisp, Rust, Go, Ruby, Python, Perl...

9

u/doublewar Mar 21 '14

imagine searching

tiled-based RPG python tutorial

vs

tiled-based RPG hack tutorial

those other language names you listed didnt have much to do with computers before becoming programming languages. But today, hack is very strongly associated with computers and programming, so making a search for the hack programming language will be a nightmare unless it becomes extremely popular.

→ More replies (2)

0

u/[deleted] Mar 20 '14

[deleted]

33

u/x-skeww Mar 20 '14

As I already said elsewhere:

It's way worse than "go", because "hack" is a programming related term.

50

u/DevestatingAttack Mar 20 '14

New language names: "Variable", "Array", "Instantiate" and "library"

34

u/x-skeww Mar 20 '14

"THE" and "AND" are also still available.

→ More replies (1)
→ More replies (1)
→ More replies (8)
→ More replies (5)

17

u/adavies42 Mar 20 '14

if you write a digital signature package in it, will it be called hack/Sign?

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

u/[deleted] Mar 20 '14

Skinniest kid at fat camp.

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

u/amoliski Mar 20 '14

Easy there, Satan.

→ More replies (4)
→ More replies (1)

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

u/[deleted] Mar 20 '14

Just imagine the loss of traffic to /r/lolphp if hack takes off :(

6

u/faitswulff Mar 21 '14

Same goes for Dart, Google's rewrite of JavaScript.

→ More replies (1)

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

u/[deleted] 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

→ More replies (2)

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)
→ More replies (2)

6

u/[deleted] Mar 21 '14

Haha, "PHP" now has a type system that is more advanced than Go!

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)

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.

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)
→ More replies (2)

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.

→ More replies (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

→ More replies (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

u/Scroph Mar 22 '14

Does this still have the T_PAAMAYIM_NEKUDOTAYIM error ?

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

u/[deleted] 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.

→ More replies (12)

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

u/dacian88 Mar 21 '14

check the tags, if they aren't <?php ?> then it's hack enabled.

1

u/gclaudiu Mar 21 '14

That's Hack, yes.

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

u/UnreachablePaul Mar 21 '14

But do you support eval?

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

u/BilgeXA Mar 21 '14

Is there a subreddit for this language?

1

u/nsa_shill Mar 22 '14

The excuse everyone's been hoping for to start using...php? Hm.

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

u/[deleted] 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.

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/Daniel15 Mar 20 '14

You can just use something like Composer. I haven't tried it out but I think it'd work.

Unless you mean a package system for native extensions?

→ More replies (3)

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.

1

u/JW_00000 Mar 20 '14

Valid question. Why not just port another language or create a completely new language to HHVM? As Clojure/Java and Elixir/Erlang demonstrate, a perfect interoperability with the 'original' language is possible.

→ More replies (2)

-2

u/[deleted] Mar 20 '14

Awesome. These are some things I wish the official PHP would adopt. I just wish FB wasn't developing this.

Some criticisms:

  • Why are types specified with the same syntax other languages use for extension?

Their example

public function increment(int $x): int
{
    $y = $x + 1;
    return $y;
}

I'd rather see

public int increment(int $x)
{
    $y = $x + 1;
    return $y;
}

which also happens to fall inline with their "less verbose" goal. Also, can you use arbitrary types here? If I have a class MyType, can I do this?

public function foo() : MyType
{
    return new MyType();
}
  • Why in god's name are nullable types specified with ?bool instead of bool?? Do any other languages put the question mark first? Was the concern that it would be confused with Ruby's something.valid?? There's no examples of this [Ruby's way] in PHP or HACK that I'm aware of.

  • The lambda syntax. Come on. FB, you invented a totally unfamiliar syntax for this, and it's totally verbose. I have to specify a method name, and then the method signature, and then the return type for the method signature, and then what the heck is ==>? The "identity greater than" operator? Is this yielding a value!? What is it!?

Make the syntax sane:

var $xPlusOne = int $x => $x + 1;

or, to rewrite the example provided:

void test()
{
    $y = 'baz';

    echo string $x => {
        $x . $y;
    }
}

http://msdn.microsoft.com/en-us/library/bb311046.aspx

http://www.secnetix.de/olli/Python/lambda_functions.hawk

10

u/dparoski Mar 20 '14

Engineer working on Hack here.

Syntax is one of those things that people can debate about endlessly and where individual's opinions tend to change over time (i.e. the programmer's first impression is often different than how the programmer feels about it after having used it for a little while).

Hack's syntax was generally driven by few competing concerns, including: brevity, familiarity for programmers who are already familiar with PHP and other languages with similar syntax, smooth interoperability with PHP, the ability to easy search a code base with regex-based tools ("grep-ability"), and avoiding genuine ambiguities between different language constructs.

For example, for lambda expressions we opted to go with "==>" because we didn't want to conflict with PHP's "=>" symbol which is currently used with array literals, foreach, and yield expressions (and might possibly be used for other things in PHP 5.7 and beyond). We figured "==>" would be recognizable enough that people would know what was going on. Yes, it would technically be possible to co-opt the "=>" symbol for lambda expressions, but then you'd have genuine ambiguities that would need to be resolved by arbitrary disambiguation rules (for example, you'd have to decide whether the "=>" in "array($x => $x+1)" was a lambda expression) and we didn't want programmers to get frustrated or confused in such cases, plus we wanted to make sure lambda expressions were easily recognizable to readers of the code.

2

u/Uncompetative Mar 21 '14

I loved reading the explanation behind the choice of the ==> here, I found it very amusing, usually CS is so dry:

http://docs.hhvm.com/manual/en/hack.lambda.operator.php

5

u/Nomikos Mar 20 '14

The lambda syntax. Come on. FB, you invented a totally unfamiliar syntax for this, and it's totally verbose.

The first example seems silly, but if you don't need a function that returns a function they're rather compact: http://hacklang.org/manual/en/hack.lambda.examples.php

and then what the heck is ==>?

Aliens!

3

u/[deleted] Mar 20 '14

Ah, okay. So their lambda syntax is sane, but it's the closure syntax I'm complaining about. Thanks for clarifying what ==> is.

Now I wish they co-opted ->. ==> looks too much like a comparison operator to me (not that => doesn't).

→ More replies (4)

5

u/pipocaQuemada Mar 20 '14

Why are types specified with the same syntax other languages use for extension?

What languages other than C# use ':' for inheritance? Also, ':' or '::' has been used in dozens of languages for type ascription dating back to the 70's. It's not a new syntactic invention by any means. Check out e.g. SML, OCaml, Haskell, Scala, F#, Clean, Miranda, etc.

The lambda syntax. Come on. FB, you invented a totally unfamiliar syntax for this, and it's totally verbose. I have to specify a method name, and then the method signature, and then the return type for the method signature, and then what the heck is ==>? The "identity greater than" operator? Is this yielding a value!? What is it!?

I assume you mean the snippet

function foo(): (function(string): string) {
  $x = 'bar';
  return $y ==> $x . $y;
}

I don't really know Hack, but it looks like it's the equivalent of the C#

Function<String, String> Foo() {
  String x = "bar";
  return (y => x + y); 
}

That is to say, you neither need to specif a method name nor a method signature, and ==> is the actual syntax for the lambda. It's not really that strange, especially because a number of languages use => for lambdas. Since it's a first class value, you can return it from a method, and if you want to give it a type, the type is "function(string): string".

1

u/[deleted] Mar 20 '14

I wondered if the type following the signature was a functional programming thing. Seeing as FB works with OCaml, I shouldn't be surprised.

Yes, I was (unintentionally) referring to the entire closure. I thought that was their solution for lambdas. /u/Nomikos pointed this out.

1

u/bstamour Mar 21 '14

C++ also uses : for inheritance. Probably where C# got it from.

4

u/TJ09 Mar 20 '14

Personally, I've found that return types get lost inside function modifiers.

Especially when you have something like "public static async function"

4

u/gclaudiu Mar 20 '14

I don't work on the Hack team, but I write Hack every day at work. Being able to grep for functions easily without knowing the return type is pretty cool. I also find it easier to read, as you point out.

→ More replies (2)

1

u/[deleted] Mar 20 '14

But that would be

public static async void Foo() {}

It hasn't been an issue for me because the type is always preceding the name. C# even enforces this - it's invalid not to order the type and name this way.

With IDEs, it's even less of an issue because they tell you what types you're dealing with. The same would be true with the type at the end.

Nixing IDEs, to me, I'd be lost with the type at the end, especially because developers have so many different styles regarding that part of code styling.

public static async function() : type
{
    ...
}

public static async function() : type { ... }

public static async function() : type {
    ...
}

public static async function($foo, $bar, $baz) : type {}

public static async function(
    $foo,
    $bar,
    $baz) : type {}

public static async function(
    $foo,
    $bar,
    $baz)
: type {}

    public static async function(
    $foo 
    ,$bar = null
    ,$baz = "qux")
: type {}

    public static async function(
    $foo 
    ,$bar = null
    ,$baz = "qux") : type {}

1

u/[deleted] Mar 20 '14
public static explicit operator int

3

u/Daniel15 Mar 20 '14

Also, can you use arbitrary types here? If I have a class MyType, can I do this?

public function foo() : MyType { return new MyType(); }

Yeah, that should work. There's also a "this" return type which specifies that the method returns the class itself (usually for method chaining / fluent APIs)

class Foo {
  public function setBar(string $value): this {
    $this->value = $value;
    return $this;
  }
}
→ More replies (2)

0

u/XenGi Mar 21 '14

So as of the examples I found the language looks exactly like PHP. Why should there be another ugly language nobody can write correctly?

1

u/gclaudiu Mar 21 '14

I doubt that if you take a Hack file and remove the pesky dollar signs you'll see it the same way. What Hack adds on top of PHP is immediately visible once you start using the language.

→ More replies (1)

-6

u/[deleted] Mar 20 '14

Sorry but first a PHP engine called "Hip Hop" and then Hack, can I ever take any Facebook technology seriously, why not just use PHP?

-5

u/Caminsky Mar 21 '14

What's wrong with PHP? I think it works fine. I mean, wouldn't it be better just to work with the PHP group and improve it with them?

4

u/myalternatelife Mar 21 '14

Did you read the "Motivation" section of the announcement post?

→ More replies (1)

0

u/[deleted] Mar 20 '14

[deleted]

3

u/Daniel15 Mar 20 '14

There may already be a task in their bug tracker about it. If not, create it so people can upvote it. I know they have a task around XHP syntax highlighting but I don't think that's been implemented either.

1

u/gagichce Mar 20 '14

not on it's own

0

u/[deleted] Mar 20 '14

[deleted]

2

u/codygman Mar 20 '14

What features do you think were inspired by Java? Static typing? I think that may have been inspired from somewhere else such as Haskell or Ocaml ;)

0

u/[deleted] Mar 20 '14

[deleted]

5

u/tedreed Mar 21 '14

Isn't it identical to C++ templates, which well predate Java generics?

→ More replies (1)

2

u/MacASM Mar 21 '14

Actually is much like C# than C++.

→ More replies (2)

1

u/Aatch Mar 21 '14

Many of the features are actually inspired by C#, including the async support and nullable types.

1

u/dacian88 Mar 21 '14

java is faster in terms of number crunching, but the hhvm servers don't do heavy computation, just tons of IO, which hhvm is really good at.

→ More replies (2)

0

u/lechatsportif Mar 20 '14

There is no elephant here, please move along! :) I would also like to know this as one of the main criticisms against the entire HHVM concept is the JVM is already out there. From an outside perspective it simply looks like Facebook is unwilling to or unable to corral this gargantuan herd of php developers that simply produce unending amounts of php.

1

u/[deleted] Mar 20 '14

[removed] — view removed comment

7

u/TJSomething Mar 20 '14

Given that the original motivation for using HHVM is because PHP was too slow, I assume there's good performance.

10

u/neoform Mar 20 '14

I like stats/numbers.

4

u/fisherrider Mar 20 '14

Here are some stats / numbers on hhvm performance: http://hhvm.com/blog/1817/fastercgi-with-hhvm.

1

u/[deleted] Mar 20 '14

Sorry bro, hackers function on gut instinct, after taking shots of Red Bull/vodka and cranking out 1000s of lines of JS and PHP, numbers take too much effort to look at.

0

u/[deleted] Mar 21 '14

[deleted]

5

u/myalternatelife Mar 21 '14

Yes. Facebook, in fact, is using HHVM.

0

u/[deleted] Mar 21 '14

[deleted]

1

u/DominoTree Mar 22 '14

I have been using it in production for about 30 days, and the speed improvements I've seen, without modifying my code, are nothing short of astonishing.

41

u/[deleted] Mar 20 '14 edited Mar 20 '14

[removed] — view removed comment

25

u/Daniel15 Mar 20 '14 edited Mar 20 '14

For what it's worth, Hack supports concurrency (well, asynchronous operations) in the form of async functions with an async/await paradigm similar to .NET 4.5. There's not much in the documentation about it, but you can have multiple database queries running in parallel and continue when they're all done (and we use this internally at Facebook quite frequently)

2

u/jadkik94 Mar 20 '14

I wouldn't consider Python 2 vs 3 fragmentation, it's just the migration process. You could say CPython vs PyPy vs Jython for example, but each of those has its own use case I guess.

1

u/leofidus-ger Mar 21 '14

if hack were a new language, it would seem to have little to recommend it beyond java or c#

To be fair, php (and by extension hack) has a completely different purpose than java or c#. I have yet to see somebody calling java via CGI, and it would probably perform pretty poorly in that scenario. It's better compared to python or perl, or maybe EcmaScript/JavaScript (when thinking of Node.js).

That also excuses lack of concurrency for me: php is for delivering a webpage within a few milliseconds, not for complicated things that require more than one thread per page request. And despite all its shortcommings, it's pretty good at that one task.