
Hack Isn't PHP - jimhart3000
http://www.marco.org/2014/03/21/hack
======
StevePerkins
I'm not much of a PHP coder, so I tend to watch these flamewars from a
distance on the sidelines.

However, I've never really understood why people criticize or mock Facebook
for pouring so many resources into PHP. For building cross-compilers,
toolchains, and syntactic extensions on top of a language that is seen as a
fundamentally weak foundation.

I mean, I DO understand all of those criticisms. I just don't get how the same
people can then turn around and use CoffeeScript, TypeScript, Dart, and even
Node.js on the __server-side __. Compared to a JavaScript foundation, PHP is
bedrock!

~~~
deckiedan
I think you're just trolling. But on the off-chance that you may actually be
interested in discussion from someone who does a lot of JS, has done a lot of
PHP:

No, they're different. Firstly:

\- js is the only choice in browsers. for server stuff, you have an almost
infinite choice.

\- javascript has warts, sure. but if you stick to "the good parts", then it
is possible to use in a relatively sane manner. the compile-to-js languages
are trying to make it easier to use the good parts, and harder to use the bad
ones.

\- node is different, in that bizarre though js may be, if you have to use it
in the browser, there is a kind of logic to using it on the server as well.

~~~
ceejayoz
> if you stick to "the good parts", then it is possible to use in a relatively
> sane manner

Is there any language for which this is _not_ true?

~~~
deckiedan
well, malbolge, for one. :-)

I may just be biased against PHP.

Facebook, at least, believe that it does have enough good parts to make it
worth while, so my opinion is just that. My opinion.

I feel that JS has the following good points:

closures, anonymous functions & enough of the 'lisp-zen-nature' to be quite
powerful. The prototypal inheritance is a bit weird, at first, and a little
ugly on its own, but actually is quite powerful.

It's simple enough that any non-js programmer can pick it up pretty quickly.

PHP has all the usual well known issues, but has the following problems that
JS doesn't:

a vast vast vast multi-level standard library, with many different ways of
doing things (mysql, mysqli, pdo...) all of which are built in (or not, you
can't tell until run-time). the various different php.ini settings which
actually change how the language works (eg. 3 different 'escape to HTML'
tags). although functions are 'considered bad practice' to use, there isn't a
single source of truth on how to write it well. the documentation is a sea of
misunderstanding and examples of how to abuse functions and do things which
aren't non-obvious (the comments on each page). JS objects generally have
methods attached for doing the various operations on them. php has a bit of
that, but mostly external functions that you pass arrays or whatever to. That
can be just a stylistic thing (being more 'c' like) but it also means you end
up having to know - just to use the language at a basic level - that it's
array_splice($a), sort($a), array_rand($a), strpos & string_replace, etc.

JS is really quite a small language. You can read crockford's, 'the good
parts' in a day, including all the bits to avoid. PHP is a very big language.
To write a 'the good parts' of it would require a much longer book, as you
can't use the recommended parts without understanding pretty much of the whole
language.

------
nly
> This is exactly what the PHP world needed: making its already-fast
> performance many times faster (amplifying one of PHP’s biggest advantages
> over other common web languages)

I think PHPs speed is largely exaggerated here. The interpreter always used to
be slow, and before the bytecode cache it was plain awful. Im pretty sure it
only ever got away with it because so much of the standard library is thin
wrapping. Is it really faster than CPython like for like?

~~~
redwall_hp
I should have stopped reading here:

"Most non-PHP developers judge the entire language by bad code snippets
'written' (mostly copied and pasted) by amateurs for PHP 4"

The old "stop hating on the only language I know! It doesn't have flaws, there
are just newbies using it!"

There is plenty wrong with PHP, to this day. When people criticize PHP,
they're not usually talking about PHP 4. They're talking about 5.4+. There's
some seriously lunacy in the core language. Some of it is there for legacy
reasons, and some is brand new.

~~~
goforit1223
How about providing some examples that aren't obscure edge cases that are
easily avoidable?

------
RossM
Zend the organisation, is probably what Marco meant when referring to poor
stewardship, instead of the OS project Zend Framework.

I like Hack because it explicitly doesn't support[0] a bunch of cruft from
PHP. It feels a lot to me like the BC-breaking PHP.next people want - easy to
switch to for modern applications, but not hindered by supporting PHP 4 code.
Bit early to start pointing fingers at it's future though.

[0]:
[http://docs.hhvm.com/manual/en/hack.unsupported.php](http://docs.hhvm.com/manual/en/hack.unsupported.php)

~~~
jimhart3000
> Writing list(, $b) = array(3,4) is not allowed. Instead use $_, i.e.:
> list($_, $b) = array(3, 4).

Not that I think the former is good practice at all, but isn't the latter a
kind of weird use of what is a valid variable name?

~~~
wting
Using _ as a throwaway variable name is idiomatic in Python, Haskell, and Go.
Looks like they're pushing the same idiom in Hack, which I'm ok with.

~~~
agumonkey
AFAIK in Haskell it's not a throwaway variable, a pattern with _ will not
create a binding at all. I don't think Python does this, maybe Go.

~~~
MBlume
Python doesn't have language support for the idiom -- trying to evaluate

lambda _, _: None

gives

SyntaxError: duplicate argument '_' in function definition

but tools like pylint will silence unused-variable warnings if the variable
starts with '_'.

~~~
agumonkey
Thanks for the verification. But even a bit of syntactic convention won't be
enough if python create a unnecessary binding.

------
twic
> PHP isn’t a great language, but it is a good language [...] it’s just as
> possible to write good, well-structured code in PHP as in most other
> languages

That isn't what "good language" means.

~~~
wvenable
Yes it is. You probably haven't written code in a bad language, but they
exist. Most programmers are pretty lucky these days.

~~~
Arnor
Does VB count as a bad language?

~~~
krapp
I vote yes.

------
nemothekid
>It’s developed and supported exclusively by one huge web company, and they
may decide to deprecate and replace it in a few years as their technical needs
change or its core engineers move on to new projects.

Thats an interesting sentiment. The exact same could be said for languages
like Go (Google), C# (Microsoft), Rust (Mozilla) and platforms like NodeJS
(Joyent). In any case it doesn't seem like too much of a worry. Cassandra came
from Facebook, and was well done enough that another company came in and
picked up development when Facebook left it.

~~~
jimhart3000
Objective-C as well.

~~~
Delmania
Nitpick, C# is an ECMA standard that has a non proprietary implementation
(Mono). I realize the best implementation is the CLR provided by Microsoft,
but is feasible that should Microsoft abandon C#, others could pick it up.

------
riffraff
> It’s developed and supported exclusively by one huge web company, and they
> may decide to deprecate and replace it in a few years

Other than the "web" bit, isn't that true of most new languages, where
$proposer is google, microsoft, typesafe, mozilla, redhat, netbrains?

Should people feel more secure if instead of being built and used by one large
corporation it was built and used by a single guy? Or should we prefer not to
have a big company supporting it?

------
korzun
This is hilarious because he was the lead developer at Tumblr.

I saw Tumblrs 'original' code base and it's a giant cluster fuck that is full
of horrible design decisions.

They are still in tons of technical debt because of it. So it's funny to see
him give an insight on PHP. Kind of ironic.

Either way, Facebook’s HHVM is not for 99% of PHP developers. Most PHP
developers need better cache coverage and proper SQL architecture and
approach.

Execution speed is not a problem for most of them.

------
dashr
> PHP isn’t a great language, but it is a good language.

So what is a great language? If it runs the largest active user app on the
planet (FB), the most widely used CMSes (WP,Drupal,EE), message boards, MVPs,
etc. Why continue the hate, then end the article on how you've chosen it as
the greatest option to run some of your systems.

~~~
eik3_de
Sure, FB, wikipedia, phpbb, wordpress. But when were those started? If you
look at what's created today in startups and open source, PHP isn't a very
popular language IMO

~~~
dashr
Lots of startups use PHP (with frameworks like Laravel4, CodeIgniter, Symfony)
for their API and sexy new front end JS frameworks that they promote. On our
current codebase, started in 2013, we decided to use PHP and have Ruby, JS,
Python apps, where appropriate, that run on top.

Twitter, famously known as a Rails, now Scala, shop, has used php throughout
its life (I know several php coders that have worked there). Their
developer/documentation area is Drupal (acquia).

But moreover, as web architectures have become more distributed and JSON
heavy, PHP has held onto its language position, especially with International
devs.

As a CTO, not a employee, its also important to consider the salaries, roles
of the people you need to build the platform.

SF Rails
[http://www.indeed.com/jobs?q=rails&l=San+Francisco,+CA&rbt=R...](http://www.indeed.com/jobs?q=rails&l=San+Francisco,+CA&rbt=Ruby+on+Rails+Developer)

SF PHP
[http://www.indeed.com/jobs?q=php&l=San+Francisco,+CA&rbt=Sen...](http://www.indeed.com/jobs?q=php&l=San+Francisco,+CA&rbt=Senior+Software+Engineer)

Then look at Non-US prices. Can't find a recent blog post where someone
reported on salaries by language.

------
thes_kumar
It not just the performance or code snippets available on internet for a
particular language that matters to a programmer. The community around the
stacks you are using to build the product is equally important.

------
eik3_de
> it's easy to learn

compared to what? IMO an easy to learn language has very little surprises, is
consistent and names things intuitively. Would you say that php as the
language is easier to learn than ruby or python?

------
gaelow
Great article, pretty much sums up my opinion on the language. (And the same
goes for Dart, TypeScript and many other `Newspeaks`: "Run in masses towards
our beautiful shiny freedom handcuffs!")

------
neuroscr
>pure PHP will become a less-tested second-class citizen on HHVM

Not really true because HHVM has to run basic PHP before it can apply the Hack
annotation. You can pull out the annotations and it's still PHP.

------
Jtsummers
Question about PHP, is it the BASIC of the web dev languages? Easy to write
terrible code, possible to write good code, derided by many, loved by many of
the same (secretly).

------
killertypo
so new language built by mega corp on top of debated language hasn't garnered
enough trust and buy-in to facilitate mainstream use?

Seems fair - I do like the static typing of hack though. Weak typing has its
place but it can become a real PITA (looking at you javascript).

~~~
ken_railey
Static and "weak" typing are not mutually exclusive.

~~~
kansface
C comes to mind.

------
gmack
He says it's like "PHP++" but I like to say it's more like P#P.

------
nsmnsf
> Expert Sexchange

Hahaha! Bigotry is funny! Hahaha!

~~~
vezzy-fnord
How is this bigotry? It's one of the oldest puns on the web.

~~~
MBlume
The question is, what's going on if you do a stack-trace on why people find
the joke funny. I think there's a certain amount of "haha, it says sex now"
(same as with the [no sex cover]([https://github.com/cmheisel/nose-
xcover/](https://github.com/cmheisel/nose-xcover/)) but I suspect there's at
least some element of "sex change, that's gross and strange and weird, haha"
which is pretty problematic.

~~~
DanBC
I think it's not "sex change Urgh weird and gross" but "sex change haha wow
unpexpected".

A bit like PenIsland - or PenisLand. They get a lot of traffic from it.

I agree it is problematic if people are uncomfortable with the idea of gender
reassignment and using that for humour. But then maybe that's a way those
people use to get over those feelings of awkwardness and move to a place of
acceptance?

