Like many people, many years ago I learned php. It was easy to deploy, and make simple dynamic websites. Many hosting services provided support for it. I was quite happy to use it for these things.
Then in 2008 I interned at Facebook. At the time, there had not yet been any attempts to improve the language by Facebook itself. Using php in an actual codebase - real world software - made me realize just how terrible it was. I vowed to never use it again. I even presented some of the worst aspects of php in my intern presentation to the executive team. Mark was quite intrigued. At the time there were talks of how to deal with many of the problems, but nothing had been figured out by time I left.
Its deficiencies are too numerous to simply list here, so I'll give you a high level summary (which many have also said similar things). Php is a giant hacked language originally not designed for real software and then features added on. It's syntax is the worst of any used language; it's language features are severely lacking; its implementations are contradictory, confusing, and destructive. In short, it is not easy to read, it is easy to shoot yourself in the foot, it is not able to scale both in complexity and performance; and its libraries are a mess.
Just because some orgs can wring a production system out of it does not mean it's the bee's knees. Far, far from it.
PHP is functional, I'll give it that. But arguing it's merits in a world that has Rails, Django, Node.js or even Chicago Boss, is going to lose you friends amongst people who appreciate elegance and speed in their libraries and applications.
As if you couldn't guess, my personal opinion is that PHP is one step up from CGI scripts in Perl5. PHP5 gained mindshare because your grandma could figure out how to embed a variable in a template and toss it in a directory that apache was already hosting with mod_php. And that, my friends is why we're even talking about PHP.
But more to the point, if anybody knows how to use PHP properly I'd think it is somebody who has worked at Facebook, and you can't just dismiss natmaster's complaints with hand-waving that he must not have been doing it right.
Well, considering the scenario he described in his own post, it's obvious that PHP wasn't used in the right way. Working at facebook itself, unfortunately, means nothing as i have no idea how their code actually is and what natmaster was doing there.
> Well for what it's worth, I keep reading that from people whose exposure to programming languages and techniques is limited to making LOB applications in PHP and maybe one or two other lowest-common denominator languages.
For what is worth, i've seen PHP applied with different patterns and architectures in scenarios that were pretty wide, powering millions of contacts daily. It's probably because of this that i learnt that it's actually a well-done language whose only fault is that it isn't popular among engineers and mostly used by amateurs. But this has nothing to do with the language itself.
What many folks forget is that the version of PHP Facebook has in Production (HipHop) is not the same version most have when they deploy PHP. Legacy & inertia has retained PHP at FB but it is far better managed then what others are doing with it today.
I have a list of few points and poor excuses used by folks to justify PHP as language of choice in today's times: http://www.theroadtosiliconvalley.com/technology/php-coding-... I am sure if Facebook were starting up today they would not choose PHP as their primary language of choice.
Then just list a few of them. Your comment seems highly subjective and opinionated without any concrete examples.
However, these is still a lot of vitrol for PHP. Because it is so easy to use, many people are able to pick it up without any prior SE experience--these people tend to create poorly-designed, slow-running, and, perhaps worst of all, dangerous (vis a vis security) code.
The other major complaint that exists has to do with inconsistency/insanity in PHP's function signatures/naming/evolution. For example: mysql_escape_string and it's sister, mysql_real_escape_string. Although, anyone working with modern PHP probably will never touch these functions.
What is overlooked is that it has an extensive base of developers, it DOES scale (this is proven), and the language is improving (as well as the tooling (PHPUnit, XHProf, CI tools), frameworks, package management etc). And although Facebook does use it, it's important to note that, AFAIK, PHP only exists as a thin layer in between "display HTML" and "communicating with backend servers which are going to handle the majority of the work, save for presentation-layer type stuff."
There are a few alternatives to PHP, but they each have their warts too. Ruby is hilarious slow, for example.
[citation needed]. Also, relevant Stack Overflow debate is available. [1] TL;DR: yes, of course Ruby is slower than, say, C, but today's bottleneck isn't hardware, it's developer productivity. (Developer time costs way more than hardware.)
[1] https://stackoverflow.com/questions/2529852/why-do-people-sa...
I even did some tests a year or so ago when I was writing a script to merge together data from multiple log files and a couple of databases, including data transformations, merging/collation and sorting of, oh 100GB or so of raw log data a day.
My first tests with Ruby were running pretty slow, so I decided to write the script out as I'd planned in both Ruby and Perl and compare the results on subsets of the data.
I used none of Ruby's OO features, I just did straight simple data structures, hashes and arrays, etc. Ruby has far better infrastructure for dealing with these things built in, and so I wrote the Ruby script in a couple of hours. The Perl script took me a couple of days--admittedly my Perl is rusty, but I wasn't doing anything complicated. But the language just doesn't have as much stuff built in.
Anyway, at the end I had two scripts with exactly the same logic, and I'd even had to implement some things (like Ruby's Array#uniq, which I assume (but don't know) is written in C) from scratch in Perl. So yeah I wasted 16 hours on the Perl script, but you could follow them line by line and they were identical.
Run them one after the other to compare, and the Perl script is literally 100 times faster and uses a tenth of the RAM. I told my Python-loving friends about this and they guffawed at the silly Ruby guy, but it was depressing.
So yeah, Ruby is slow at runtime compared to other languages. Usually that doesn't matter, but sometimes it matters a lot.
The misunderstanding of when an MVC architecture is appropriate, and when to (and not to) use the framework, is the mark of someone who has not yet really understood how to use Rails effectively.
A lot of this is because 1) they jumped on the rails bandwagon without understanding it or if it suited their needs 2) after using rails to prototype their site, they now understand what their architecture should look like and want to start fresh 3) because they've joined the next circle jerk such ask nodejs
All the rest of your post is overly vague, or simply untrue. People pick rails because it has sane defaults eg. ActiveRecord but there are plenty of other gems for other database persistence layers.
Talking about productivity is a good thing because raw "power" doesn't mean anything, but I really wish we could admit publicly that Ruby is really not a race horse. It does other things awfully well and I wouldn't trade language for the world, but man, I wish it could get a free speed jump like Javascript got a few years ago.
Ruby 2.0 and 2.1 made incredible improvements to the garbage collector, a major source of our problem. We determined that it was the speed at which we were creating and destroying objects that was causing the GC to work on overdrive, which drove up CPU usage. So with the new GC improvements, we saw that usage go further and further down.
Ruby isn't a race horse.
It just turns out that when you're just plowing fields, harnessing up your prize stallion is a waste of resources.
That's until you try to scale things.
2013 was a good year for PHP. Most of the time when I hear people complaining about the language, it's as if things haven't changed since 2005.
There's a lot of horrible, badly written spaghetti code out there in PHP that doesn't exist in other languages, but there's also probably much more decent code written in PHP and I think that trend is only set to continue.
Nowadays with wrappers it's thankfully less of a problem.
Having just come off a Drupal project myself but having looked at the latest PHP additions as well as Laravel though, it seems to me that many languages are converging and borrowing from each other, which I love. Latest PHP is pretty sweet.
The way SQL is implemented and executed still primarily is one of the primary arguments against, at the very least, not learning PHP properly. And it's definitely a point in the column of any framework in any language which can say that SQL injection and remote code execution are impossible in frameworks written in that language.
PHP is not a exceptionally bad platform from a technical perspective, it usually gets the job done, is reliable, easy to operate and performant. But i guess the real reason why so many developers - including me - hate PHP is that plain PHP is pretty boring. It doesn't have opinions on anything and no exciting concepts or language features. Now you can use great frameworks that implement great ideas in PHP, but because PHP has been around for a long time, much of the code out there and still in production is spaghetti code that is no fun to work with and the only option to change that is often a complete rewrite.
Remember the immediate visceral reaction you had to the double-clawed hammer? That's exactly the reaction most sane programmers have to their first encounter with the web programming language PHP.
First of all, I didn't have a visceral reaction to that image (and I'm not sure Jeff knows what that word means), but setting that aside, the second sentiment is just wrong. PHP doesn't cause that reaction on your first encounter. Most of its ugliness is in a bunch of little things that you learn to deal with over time.
Another example. He says:
What we ought to be talking about is not how terrible PHP is – although its continued terribleness is a particularly damning indictment – but how we programmers can culturally displace a deeply flawed tool with a better one. How do we encourage new programmers to avoid picking up the double clawed hammer in favor of, well, a regular hammer?
And in the very next paragraph:
Despite the serious problems with PHP, I was forced to consider it. If you want to produce free-as-in-whatever code that runs on virtually every server in the world with zero friction or configuration hassles, PHP is damn near your only option.
I don't know how he doesn't think that contradicts his previous point. Actually, now I'm not even sure what his previous point was. Inexperienced programmers are wrong to choose PHP. But, also, PHP is the best choice available.
I won't go paragraph by paragraph, but these things really add up when reading his writing.
(If you're just trying to make yourself feel better about PHP, just remind yourself that Facebook is built in it, as are lots of other credible systems; languages are tools, and while better tools help, skill and discipline are more important).
1) As mentioned there are a number of language inconsistencies, much more so than comparable languages. This includes naming schemes for functions
2) PHP and most major projects written in it are insecure. Even up-to-date Wordpress installs are vulnerable to attacks.
3) Testing still isn't in vogue. Few projects have any testing and for those that do the testing tools aren't nearly as strong as in other languages
4) The tooling that surrounds the ruby, python, go, javascript languages is much more advanced than what PHP has even now. PHP only really got a decent package manager last year.
5) For a long time most PHP projects were procedural. Real OO was only introduced in PHP 5.
6) There is a lot of bad code written in PHP because it was so accessable.
7) Most examples of PHP projects are CMS' which don't require a ton of experience to build. You meet a lot of people who have spent 10 years in the industry that really have just managed content that don't know how to build something complex and don't have any background in data structures, algorithms etc
8) The PHP community is extremely fractured. There are something on the order of 10+ major PHP frameworks. Zend, Symfony, Codeigniter, Cake, Laravel, Kohana, Yii plus a number of more minor frameworks like Lithium, Silex etc before you get to the CMS' like Joomla, Wordpress and Drupal
3) It's definitely much better but still doesn't compare to the ruby or node communities. I think the biggest changes to the community will be a bigger focus on testing/TDD and facebook's HHVM
5)True. Wordpress and Joomla are extremely old applications. However Wordpress is still extremely popular, which is why I bring it up.
7) Would you mind adding what your experience has been? I'm genuinely interested.
Ruby really only has 2 main frameworks: Rails and Sinatra. Python and Node are more fractured, but there are generally a few main frameworks
>Facebook uses it
Not really, I mean Facebook doesn't use the PHP that a common person uses.They've made so many changes and their codebase is so huge. Facebook also uses the D programming language, HipHop, and probably more tools than I'll ever know. Wasn't chat at Facebook first written in Erlang?
For one, it's no secret that PHP was an amateur undertaking that inadvertently ended up powering >80% of the web.
It started off as a bunch of helper functions that were meant for Rasmus Lerdorf's personal use. He has frequently acknowledged that he was never particularly skilled and that PHP was never meant to be used on such a large scale. Among the countless WTF moments you would expect from a personal project, PHP once used strlen() as a hashing function. [1]
Thus, PHP ended up having a very inconsistent design and an awful typing system. It ended up becoming quite baroque, it has never had a formal specification and it has no coherent idea of what it wants to be. This is exemplified by PHP's relatively recent appropriation of Java idioms in an attempt to bring vague Nygaard OOP.
Third, it's fundamentally a templating language and it doesn't encourage any cohesive design patterns or practice. Most PHP sites don't even use frameworks, but rather go with the Mozart (or rather, spaghetti) style of copy-paste programming. There is no clear separation of concerns.
Fourth, the PHP community has always been dominated by amateurs. I can't really direct you to any objective statistics, but in general PHP has a disproportionately high amount of leechers and newbies, largely because it has been so deeply ingrained into the public consciousness as the de facto language of the web, without knowing of the better designed general-purpose alternatives.
Fifth, some concrete examples of PHP's horrific internals. [2] [3] [4]
Alternatives? Anything, really. Python, Ruby, Perl, Common Lisp, Haskell... whatever floats your boat. A minimal web framework is a trivial application to write. That's why there's so fucking many of the goddamned things.
[1] http://news.php.net/php.internals/70691
[3] http://www.phpsadness.com/
[4] http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-de... (the famous article)
Anything can be hacked around, of course, as Facebook has proven. But you could write Facebook in Bash or DOS Batch Language if you were willing to. But newer frameworks and languages that were designed with modern web development in mind are more to a lot of people's liking than PHP's style.
Really, the best way for you to answer your question is to dig in and learn how to develop a webapp using Ruby or Node.js or Python and the amazing frameworks that are built on those languages. Dig in for a couple of years and then on the other side you'll understand better. You may still prefer PHP, but even if you do, I'll bet the PHP code you write will be better for having learned how the "other guys" do things.
Of course: you need to know what you are doing. But the language itself is capable of doing almost everything, without drawbacks.
Lot of people make clueless claims about how PHP is worst than (place-latest-cool-framework/language-here). This is far from being true, read this: http://philsturgeon.co.uk/blog/2013/11/benchmarking-codswall...
So, PHP is hated in the devs world because it gave access to "amateurs" to the world of crafting software. Which is ridiculous.
I like to equate the technical community with the skiing community. The barriers to entry are tough. It takes a lot of practice to become good skier, and many that do become expert skiers instantly elevate themselves above the rest with routes, equipment, and other types of "I'm more technical than you."
So, back to hate for PHP.
The C++ and Clojure and Erlang crowd are the double black diamond skiers, and they are the first to throw hate at the green and blue skiing crowd - because, well, they've mastered everything else and since they mastered it, well, they are just better than you.
Meanwhile, you've got the PHP type skiers who are cruising the groomers, enjoying the sun and living life - pinching themselves because they are just getting the task done. They occasionally hit a black or two, and even hit the moguls to refine their turns and technique, but they are there to get shit done - which means to ski and have fun.
Then you've got the Perl and COBOL guys who just ski around the mountain and complain about all of the above, since they've been skiing for 40+ years.
Disclaimer: I am an avid skier and maintain a number of successful Web properties based on PHP. And I love the groomers...
PHP a fractal of bad design: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-de...
$foo = [];
$foo[$userSuppliedString] = 'foo';
foreach(array_keys($foo) as $userSuppliedString) {
if (! is_string($userSuppliedString)) {
die("I understand all the reasons for this behaviour, but it violates the principle of least astonishment");
}
}
Supply a string. Works fine? Try running with a string that looks numeric.I use PHP every day, it's a great language for many things including teaching programming. Every language has its quirks and i don't really think PHP's quirks are worse than others.
"The Tao gave birth to machine language. Machine language gave birth to the assembler. The assembler gave birth to the compiler. Now there are ten thousand languages. Each language has its purpose, however humble. Each language expresses the Yin and Yang of software. Each language has its place within the Tao - but do not program in COBOL if you can avoid it."
PHP is SUCKY! Because it is way to slow for 10% of websites. 90% of coders pieced together their solutions from a mish-mash of code examples they found on the web. HTML is just strewn through out because most people do their PHP inline with the HTML rather than populating variables to output all at once. LAMP has the word Apache, and MySQL in it and that means you inherit some badness that is being sold as a commodity (yeah you can run on a non-lamp but very few who do PHP do, and so you may not be compatible if you stray from LAMP which means you are writing in a non-standard way)
A standard, no crazy stuff, database-backed blog+login site made in Symfony consumes ~60MB of memory. Then discards it and starts again. On each request. Even if the bytecode itself is cached, it has to create/register all the classes and global objects it uses every single time.
I think people should find that at least weird and probably scary. Other languages, which separate continuously running application servers from the page serving, do not do that.
If you tell a room full of Java and C++ developers with no experience to PHP, that on every request, everything gets loaded, and at the end of the request, everything (and I mean everything) gets torn down, you'll get a bunch of blank stares.
However, the web, in its nature, is stateless. So, having a language where nothing persists across requests (except that which you store/retreive by using cookies/session data) is suited to the web. Also, not having to worry about memory management or thread-spawning helped to make PHP the simple, accessible language that it is. No memory leaks!* ;-)
In loadtesting, I've found that PHP is almost always CPU bound. Yeah, you might be loading and unloading 60MB of memory each time, but a) caching (send those 304s!) and b) it's not like your memory is going to 'go bad' from loading/unloading Symfony.
That said, there might be something to keeping Symfony loaded in memory. In my own tests, loading the classmap is one of the longest-running tasks in simpler PHP applications.
PHP is the ghetto. It might be fun or necessary when you're young and can't afford better. But, eventually people who are able, move somewhere they aren't being mentally stabbed in the face every time they pop down to the corner store. This, of course, reinforces the ghetto. As the people who can't leave are the dregs.
Nothing is as black and white as a couple sentences makes it sound. But, that is the place PHP has (deserved or no) in the programming world.
But that evolved trait now can be seen in how we conform to the ideologies and groupthinks of political tribes and groups. Homo sapiens seeks out tribes and discerns their ideologies and internalizes them and then re-propagates.
We are a species of ant-like primates, and instead of spraying chemicals or from musk scent glands, we spray ideology, the ideology of our adopted tribes.
The elite use this evolved trait of propaganda-ingesting in order to manipulate us.
Anti-php is one of the central tenets of HN ideology. To be a full member of the tribe you must internalize and re-propagate this ideology.