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? :-)

6

u/pasokan Mar 21 '14

That smiley .... the almost overpowering sense of "do you know who you are talking to"

22

u/vagif Mar 20 '14

Go on...

31

u/5outh Mar 21 '14

If you're not aware, Bryan O'Sullivan (bos) wrote the book Real World Haskell.

→ More replies (1)

2

u/gcross Mar 21 '14

So how exactly did you fall from heaven? ;-)

I kid, of course. I was definitely a bit surprised at first to see that you were the project manager for this since I thought I remembered you being common poster in /r/haskell er, but it makes sense that you'd be involved in a project that brings features of static typing to a dynamically typed world, and regardless it is certainly admirable to have experience with a broad spectrum of programming language approaches.

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.

25

u/Eirenarch Mar 20 '14

Why is this considered so special? ASP.NET can do this since day one* and C# is much more statically typed and compiled than Hack. Hell, you can even edit the code while you have stopped at a breakpoint and continue.

*In case someone is wondering you need to use the Web Site project and not the Web Application one for actual save/refresh without compile behavior.

→ More replies (5)

27

u/detroitmatt Mar 20 '14

As a follow-up, I haven't had time to look over Hack's doc very comprehensively yet. In my opinion, a lot of the problem with PHP is its standard library: The language itself has a lot of neat features that would be dangerous if abused, and the stdlib abuses them, which is the problem, but if used responsibly are powerful, flexible, and useful. Therefore in as much as the standard library is the problem with PHP, does Hack's standard library avoid these problems?

10

u/Error401 Mar 20 '14

What do you mean? Hack still keeps direct compatibility (in terms of interface) with standard PHP library functions. There are some things they left out intentionally that are overall problematic or the source of way too many bugs, so there's that.

16

u/detroitmatt Mar 20 '14

I suppose what I meant is "Will Hack have its own standard library that solves some the problems of PHP's?"

→ More replies (6)

7

u/argh523 Mar 20 '14

Funny..

  • if/then/else without {}

  • elseif (without the space between else and if)

That implies that you'd now have to write:

if ( $x > 0) {
    // foo
} else {
    if ( $x < 100 ) {
        // bar
    }
}

I doubt that's the case. But what I wrote above is what actually makes sense, and the elseif keyword would fix it. So now "else if" is just a two-word keyword, or "else without {}" isn't actually true.

But hey, it's a language based on PHP that is called Hack, so.. ;)

→ More replies (11)
→ More replies (7)

0

u/[deleted] Mar 20 '14

[deleted]

→ More replies (8)

3

u/[deleted] Mar 20 '14

The crazy dynamic things you can do also occasionally have their place, though it's certainly easy to shoot yourself in the foot.

Can you give an example of some time you'd want to use a dynamic language over a statically typed language?

(I'd argue that there is usually a way to do the dynamic behavior in static languages, by using variable constructors and disjoint unions, but I think your argument is that there are times it's nice for that behavior to be the default.)

7

u/alokmenghrajani Mar 20 '14 edited Mar 20 '14

I can think of quite a few:

  • you are experimenting with an idea. You might want to tell the type checker to leave you alone while still be able to see your code run.

  • you are refactoring some large piece of code. You want to run tests or specific pieces of code to make sure you are headed in the right direction.

  • A part of your code might deal with lots of unstructured data (e.g. json) and it might be easier to write the code without boxing all the data in what boils down to untyped containers.

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

2

u/benjumanji Mar 21 '14

Syntastic + Ghc-mod gives you all of that when editing Haskell. C# and Java both have ide's with incremental type checking. No build required. Haskell and ocaml have a repls. C# and Java have had the ability to evaluate expressions and change values on-the-fly during execution for years. What static languages are you referring to? I think it's awesome what you guys are doing for the php ecosystem, I just don't think from what I've seen that hack brings anything new to the table for someone not working with php.

2

u/UloPe Mar 22 '14

For as much flak as PHP gets, there are actually a lot of good things about the language.

Name one. (And "everybody already knows it" doesn't count)

3

u/[deleted] Mar 21 '14

How does hack compare to Python?

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

212

u/MikeTheStone Mar 20 '14

dHd

25

u/Feirlane Mar 20 '14

And then get sued by the Stargate people

0

u/[deleted] Mar 20 '14

[deleted]

→ More replies (5)

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.

18

u/seanosaur Mar 20 '14

QIQ: It's quick and easy.

52

u/SomniumOv Mar 20 '14

it's Quick Ind Qasy.

→ More replies (4)

15

u/[deleted] Mar 20 '14

Recursive like PHP.

QIQ = QIQ is quick.

→ More replies (2)

3

u/[deleted] Mar 21 '14

If you want to go with the IBM -> HAL joke it should be OGO :)

→ More replies (3)

11

u/cjt09 Mar 20 '14

It doesn't say you can't use "php" though, only that you can't use "PHP". ;)

62

u/TJ09 Mar 20 '14
$ php -r "var_dump('php' == 'PHP');"
bool(false)

Your logic holds.

56

u/Crandom Mar 20 '14

I was half expecting that to come back true for some reason, given what I've seen of PHP.

→ More replies (2)

7

u/[deleted] Mar 20 '14

Still a bad, nondescript name. At least they didn't name it "code" or something.

8

u/fabienbk Mar 20 '14

It's not like language names are usually super descriptive though : C, java, Go...

→ More replies (4)

4

u/rolandog Mar 20 '14

How about p3: "PHP Plus Plus".

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

57

u/max_t2 Mar 20 '14

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

23

u/Steltek Mar 20 '14

Moreover, "Hack" is a weird name whose principle (only?) improvement is static typing. In my mind, a "hack" language is like Perl. Quick, dirty, and able to twist reality for no reason other than "I want to".

2

u/karma-is-meaningless Mar 21 '14

Isn't it a "Hack" of PHP?

4

u/user-hostile Mar 21 '14

I think it's edgy.

→ More replies (54)

2

u/nomeme Mar 21 '14

Yeah, Hack is a TERRIBLE name.

Should have picked something starting with Ph* like

Phi, Photon, or Phase

3

u/nomeme Mar 21 '14

Even Phaaaaaaaarp! would be a better name. Thanks.

5

u/quchen Mar 20 '14

Or PH++, file extension phpp.

→ More replies (1)

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

4

u/scopegoa Mar 21 '14

Yea...

"R Programming Language" works a bit... or you just filter on Stack Overflow and hang out on QuickR for the basics.

2

u/mosqua Mar 21 '14

I think google-fu should a prerequisite for programming.

→ 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

13

u/mk270 Mar 20 '14

Thanks. I looked in hphp/compiler, but not in hphp/hack. My mistake.

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.

3

u/madcaesar Mar 20 '14

They might as well have called it "is".

→ More replies (1)

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)

3

u/GoSailing Mar 20 '14

It's very similar in function to Typescript on Javscript, where you have implemented (or are on your way to) the language as a strict superset. Did you get any inspiration from Typescript, or was it simply a convergence on a good idea?

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

4

u/realhacker Mar 20 '14

Maybe php6, but that probably wont come out until 2020

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

3

u/zanzilove Mar 20 '14

Not quite about Hack - which looks really interesting by the way - but this question sparked my interest: " with thousands of engineers shipping new code twice a day".

I'm someone who wants to get into the software industry after graduating, so could you please explain what back end work is happening in a company like Facebook that requires so much intense coding?

3

u/Eirenarch Mar 20 '14

Do you consider Hack something you will want to work with if you had the chance to build Facebook from scratch or is this just something to replace the dreaded PHP in a practical way. If you would use another language which one?

2

u/okawei Mar 20 '14

Really awesome job on this. Can you go into details as to exactly how much of facebook has been refactored to use hack?

2

u/YM_Industries Mar 20 '14

Hey there,

I've just started developing a new website in PHP, so this has come at a perfect time where I'm early enough in the development process to easily migrate languages.

I have a question though: Is there an IDE for Hack, and can the IDE run on Windows? My production environment is, of course, on Linux (CentOS 5) but I'm wondering if there's a way to get all that real-time error-checking goodness that I can see in the tutorial on my dev machine.

Thanks!

2

u/gclaudiu Mar 21 '14

Even if you get the typechecker to build and run on Windows, you won't be able to get HHVM, the runtime, to build on Windows.

I would suggest developing on a dev machine that runs Linux, or just dual-boot Linux. There's no IDE for Hack, but Hack is supported on vim and emacs. You can pretty easily build a plugin for your IDE of choice, just run hh_client --json to get a JSON with all the errors the typechecker finds. You can, of course, just run the typechecker from the command-line if you want.

2

u/[deleted] Mar 21 '14

You can run Linux in a VM and develop that way. Lots of different variations on that theme.

2

u/lpw25 Mar 21 '14

Their tutorial (http://hacklang.org/tutorial/) is running the type checker in the browser, compiled from OCaml using js_of_ocaml. So it's probably not too hard to get it to run on Windows.

1

u/morricone42 Mar 21 '14

Thank you for publishing this. All those nice features and you already have async/await!

1

u/catosmandros Mar 21 '14

I can understand why FB started with PHP, easy to develop and iterate ... they already have a giant codebase in PHP, migrating a codebase is expensive ... But now they have written a compiler to C++, a compiler to a VM bytecode and a runtime for it, extensions to PHP, a type checker, and an inference engine. That's a lot of things to support something that can only be fixed from the beginning.

Wouldnt it had been easier to migrate to another, less lacking language?

1

u/nsa_shill Mar 22 '14

How do you all feel about PHP, in general, as compared to the other dynamically typed, interpreted languages currently popular for server-side stuff? What makes investing in and building on this ecosystem worthwhile, instead of those around python, ruby, or node?

What is hack's approach to distribution (as in multiple AWS instances behind a load balancer)? Node-style single threaded execution + redis or something?

1

u/drklucavi Mar 20 '14

Would Hack be a good language for someone brand new to programming to get into?

4

u/gct Mar 20 '14

PHP in general isn't a great choice for someone new to programming, it's easy to learn but it will teach you a lot of bad habits and you won't have any reference to see all the bad things that it does. Try something more reasonable like python for your first go around.

4

u/jephthai Mar 20 '14

I think all languages teach bad habits. Much like it may not matter what language you learn to write essays in -- it's ultimately writing. Experience fixes bad habits more than choice of languages does.

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

1

u/[deleted] Mar 20 '14

I think I finally understand cultural appropriation. I'm so sick of people using the word hack for things that are most certainly not hacking.

You should name your next language Exploit so people in the security industry can't talk about anything without sounding like they're dropping buzzwords. One named Malware would be really cool.

I'm a Malware Research Engineer and I do some Exploit development.

Oh, so you work at Facebook?

→ More replies (30)

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

2

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

Let the PHP flow through you.

That sounds extremely painful...

→ More replies (1)

0

u/[deleted] Mar 20 '14

[deleted]

43

u/flash__ Mar 20 '14

"You underestimate the power of the client side."

14

u/[deleted] Mar 21 '14

I don't trust the client side.

→ More replies (4)

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

u/grabnock Mar 23 '14

And im guessing their method didn't involve casts or compiler switches...

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

1

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

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.

2

u/UnreachablePaul Mar 21 '14

Just a little

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/[deleted] Mar 21 '14

They should have called it HPH, for Highly Polished sHitpile. But I'm just a hater.

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.

1

u/zefcfd Mar 24 '14

Let's not forget googling "chef recipes"

→ More replies (19)

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.

4

u/[deleted] Mar 21 '14

You're forgetting our beloved iterator, Δ.

→ More replies (3)

2

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

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

1

u/[deleted] Mar 21 '14

That's why they picked such an appropriate name.

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

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.

1

u/wildcarde815 Mar 20 '14

Looks like they've been working on an llvm back end for it as well.

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

u/gimmethrowaway Mar 21 '14

Really cool interview thanks for the link.

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.

0

u/[deleted] Mar 21 '14

[deleted]

→ More replies (11)

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

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)