Hack Isn't PHP
marco.orgI'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!
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.
EVERY language is "relatively sane" if you only "stick to the good parts". That argument is basically a tautology.
As for the logic of using a single language throughout your stack, I would argue two points:
[1] It's a myth. If you are a professional software developer, you are going to learn multiple languages... and if you're a GOOD software developer, then this excites you rather than bums you out.
So you're using JavaScript on both the client-side and server-side. Okay, how do you get information from your database without learning SQL? Just stick with MongoDB as the only datastore you will ever use? Document stores are great for the things that document stores are great for (another tautology), but suck horribly when you try to shoehorn them into situations calling for a relational database.
What about the HTML and CSS knowledge you already need to work on the client-side? Do those "not count", because a JavaScript developer usually happens to know them? Nonsense. Doing real work requires knowing multiple languages, because different ones are better suited for different domains.
[2] I would argue that the skills and considerations required to do non-trivial work on the server-side are generally different from those skills needed to do non-trivial work on the client-side. You may be smart and/or experienced enough to master both domains, but you approach design and coding issues differently in those domains.
If you take a developer who is senior on the server-side, but is so junior level on the client-side that he or she barely understands the DOM, then they will struggle at first in the other context. Vice-versa if you take a senior client-side web developer and throw them into the backend world. You're going to need to learn completely different skills, quickly. I'm not convinced that clinging to your "home" language really speeds up that process, rather than impairing it.
I agree that any language is relatively sane when sticking to the good parts, and even that is a stretch with JavaScript.
The code sharing benefits are very real, while backend developers may need to learn a bit about the dom whereas frontend developers may need to learn a bit about sockets / file handles whatever, having a shared language (and libraries) is immensely powerful.
I work on a clone of CouchDB in JavaScript, it also works as an (immature) fully functional server side clone running 90% shared code.
The most used libraries in npm are shared between client and server, it has very real benefits
Fair enough. I actually don't use node, or js on the server. :-)
I still kind of like the idea though, of having only one source for (say) object definition, which is shared somehow between the client and server code. Being able to use the same unit tests to check my client side models as server side ones.
Maybe you could do it the other way around though - having your objects from your SQL Schema (or ORM, or whatever) generate the basic JS models... I dunno.
I totally agree that you need multiple languages, and that knowing multiple languages is incredibly valuable - and a lot of fun. I wrote a basic scheme in python for fun, and have a haskell textbook on my desk in front of me right now :-) - But I also feel that there should be some way that by using one language for all of your application logic (client and server side), there could be a benefit.
Sure, DOM manipulation is it's own weird thing - as is database querying, and document styling,- but the application logic that is done clientside and server side is very similar, I find.
> 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?
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.
ooh, ooh! Unlambda!
```s``s``sii`ki `k.*``s``s`ks ``s`k`s`ks``s``s`ks``s`k`s`kr``s`k`sikk `k``s`kskBrainfuck?
> 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.
I don thinkt that makes any sense. Should we also use js to implement the OS for the server? If js is good for server-side use it, if not use something else.
My main issues with php is that I dont trust the language and standard libraries to behave as I expect. There are simply to many strange type conversions, silent errors and strange behaviour going on.
> I don thinkt that makes any sense. Should we also use js to implement the OS for the server?
We don't normally develop the OS ourselves, so what language it was written in is irrelevant. Same goes for runtimes, libraries, etc. If we're not responsible for maintaining it, it should not matter what language it was written in. Naturally, the "same language on client and server" argument can only apply to code we develop and maintain.
My argument was badly put.
What is the benefit of using the same language on the client and server? That the developer only needs to know one language?
The server-side code you write has to interact both with the client and the underlying OS. So you should consider how language X interacts with both client and OS, in addition to the intrinsic qualities of the language.
If we adopt a modular approach to software development, then I don't see any universal benefit to using the same language for all modules.
js might be a good server-side language, but choosing it because it works on the client is the wrong reason.
Taking PHP Seriously is a great presentation that talks about why FB is using PHP: http://www.infoq.com/presentations/php-history
> 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?
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.
How about providing some examples that aren't obscure edge cases that are easily avoidable?
> Is it really faster than CPython like for like?
It is a mixed bag. There are times where PHP is faster because it is closer to C, where as more python is written in Python. I once ran into a situation where it mattered that PHP's file_exists() is much faster than python's os.path.exists(). I have run into other cases where CPython is much better, such as python's heapq crushes a hand rolled PHP priority queue.
In practice PHP tends to be quite fast, because the standard solutions are pretty unambitious like thin wrappers around CURL, rather than actually implementing HTTP in php.
> pretty unambitious like thin wrappers around CURL
That (specific example) sounds incredibly intelligent to me.
PHP is fast - I've been there, made ~4k RPS websites in PHP & memcache.
There's one big, primary reason for it.
PHP is dumb.
You can't do clever things in PHP with the language, you have to all the clever things in how you design with it.
You can't overload functions or redeclare them later.
You can pretty much resolve a function at call-time, without worrying about decorators around it or about any meta-programming.
This makes for a fast VM in PHP, because it can make assumptions about function call-order much more than something like python.
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.
> 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?
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.
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.
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 '_'.
Thanks for the verification. But even a bit of syntactic convention won't be enough if python create a unnecessary binding.
And Ruby, and Rust. It's close to universal.
And Clojure.
It is a variable, not a language construct. The docs are just recommending `$_` as a convention over something like `$temp`.
> 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.
Yes it is. You probably haven't written code in a bad language, but they exist. Most programmers are pretty lucky these days.
Does VB count as a bad language?
I vote yes.
q.v. JCL
Job Control Language - Old timers love this. The rigidity of it fits the mainframe philosophy.
"Bad language" is subjective, just like practically all discussions on this topic.
>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.
Objective-C as well.
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.
I'm pretty sure that I remember Objective-C (under gcc) from way back.
> 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?
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.
> 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.
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
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...
SF PHP http://www.indeed.com/jobs?q=php&l=San+Francisco,+CA&rbt=Sen...
Then look at Non-US prices. Can't find a recent blog post where someone reported on salaries by language.
Couldn't a similar rationale have justified (still justify?) Cobol in the 90s and Java today as "great languages"?
Argument from popularity doesn't denote quality. I'd hardly say he's "continuing the hate", quite the contrary: him calling PHP a good language is likely at odds with most of HN.
Quite honestly, there's only a couple or so languages that I would truly describe as "great".
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.
> 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?
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!")
>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.
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).
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).
Static and "weak" typing are not mutually exclusive.
C comes to mind.
He says it's like "PHP++" but I like to say it's more like P#P.
> Expert Sexchange
Hahaha! Bigotry is funny! Hahaha!
I think you're being overly sensitive. It's funny because it says sex, not because it's making fun of transgenderedness. People are easily amused by cis hetero sex too. Sex is funny no matter who is doing it.
How is this bigotry? It's one of the oldest puns on the web.
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/) but I suspect there's at least some element of "sex change, that's gross and strange and weird, haha" which is pretty problematic.
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?
I think it's a combination of the fact that our society has historically had a very perverse relationship with sex, in the sense that it is simultaneously icky, taboo and not to be talked about, yet also crucially important for brownie points and social cred.
However, the main reason is simply the fact that it's such a captivating example of unintentional humor, and what happens when you don't pay attention to your image. In many ways, it's the linguistic equivalent of the famous rabbit-duck optical illusion. It's curious and elicits a response when one realizes the double entendre.
It's hardly problematic, unless your definition of problematic is for everyone not to be dull as cardboard to every little example of unintentional humor in their lives.
Jinx :p
It's arguably making fun of people who have gotten a sex change.
That's sort of like reading this bash quote: http://bash.org/?574642 and saying "What's so funny about people being shot?!"
How is that bigotry?
Against people who actually need sex changes.
I don't agree that it's bigotry though.
Laughing at the word sexchange is a little insensitive to people who have had a sexchange.
Transgender people have it tough. Give them a break.