top | item 6460425

Taking PHP Seriously [pdf]

129 points| memla | 12 years ago |raw.github.com | reply

148 comments

order
[+] dkhenry|12 years ago|reply
At this point we almost need to stop saying facebook programs in PHP. I know this was defending PHP, but look at what is happening. Facebook ( big engineering firm, lots of developers and resources ) could not get php to work for them short of rewriting the core (HPHP ) and then adding on features to the language that most other languages have determined are useful enough to be baked into the language.

Here is my TL;DR of this article. PHP is bad we all know this and accept it. Facebook has made it better by keeping most of the syntax and chucking everything else out the window. Run your stuff on HipHop ( unless you need extensions in which case your OOL )

[+] kmavm|12 years ago|reply
Video of the talk is not up yet, and it's a little cryptic with just the slides. But one of the points I was trying to make is that PHP actually makes you more likely to be successful than a lot of its competition. The lolsy stuff on "The Case Against PHP" slides is all you ever hear because ... well, because they fit on slides. They're immediately, obviously weird. But these problems are shallow. There are deeper properties of the language and its interaction with the environment that overcome those problems, and then some.

Also, it's a little obscure for languages like PHP where we're unused to making architecture/implementation distinctions, but if HHVM is good then PHP is good. It runs the same core language as php.net. To the extent we don't, it's likely to be a bug these days. I think HHVM is a better implementation of that language than php.net, but I am biased, and that isn't the point of the talk. We're also chipping away at running other popular programs, extensions and all: http://www.hhvm.com/blog/?p=875

Edit: transposed sentence

[+] workhere-io|12 years ago|reply
could not get php to work for them short of rewriting the core (HPHP )

I've heard this argument before, but it's important to realize that Facebook was able to use standard PHP up until the point when they had roughly 500 million users. Unless your site has a half billion users you can't compare your use case to Facebook's.

[+] kayoone|12 years ago|reply
Yes and no.

As a matter of fact Facebook would probably have run into the same problems if they had used Ruby or Python. These problems are problems of massive scale most of us will never face. Twitter had problems running on Ruby/Rails and i bet theres a case to be made for Python too. All this says is that at the scale level of facebook you will encounter the limits of dynamic typing scripting languages, but its not a problem with PHP per se and also not a problem that should hold anyone back from choosing php/ruby/python because its premature optimization.

[+] mappu|12 years ago|reply

    >At this point we almost need to stop saying facebook programs in PHP
This isn't the first language-incompatible change they've introduced - see XHP, which used to exist as a Zend extension(?) and is now rolled into hiphop
[+] memla|12 years ago|reply
Judging by that TL;DR people would think that there's an article with pages upon pages of what Facebook decided to eliminate from PHP, and not to make it easier but to make it possible to mantain their codebase. No such thing can be found in the provided PDF.
[+] jasonlotito|12 years ago|reply
Tell Facebook that. They are the ones talking about it still.

Also, your TL;DR is a flat out lie.

[+] xkiwi|12 years ago|reply
Another hard example: A start up wants the cutting edge tech so they use hphp. The company ran out of money before it finish complied.
[+] DigitalSea|12 years ago|reply
Adams actually makes some very valid arguments in this PDF. People like to argue the superiority of languages, but at the end of the day if the result in PHP is the same as it is in Ruby & Rails, Java, .NET or whatever, does it really make what the language is? Another good point is the efficiency of a developer working in PHP. The language is easy, it's so easy to be a PHP master after a few years working in the language. It's easy to find super-talented PHP developers compared to any other language.

I like the idea of opt-in typing for PHP via Hack which you can enter by beginning your PHP code with <?hh — Facebook have essentially taken everything that is wrong with PHP, every complaint that someone has ever published in a blog post or bug report, forum or IRC channel and built it into an improvement of the language.

PHP isn't going anywhere. It might be one of the oldest web languages, but I think the PHP space is starting to get better with Facebook's contributions to the language, Laravel 4 being a solid PHP framework and we can't forget that most Yahoo! products are built using PHP as well (even the recently acquired Tumblr is coded in PHP). Flickr! is probably one of their biggest PHP applications.

Event hough Facebook appear to have resolved the many complaints and problems of PHP, I am sure people will still find a way to complain about the language that powers most of the web...

[+] Almaviva|12 years ago|reply
Are the complaints about PHP even controversial? The built in library functions are a mess, and mostly terrible. The syntax and basic language are overly verbose and have layers upon layers of cruft. The type and object systems are grafted on, and have so many gotchas and inconsistencies that it takes many months to understand enough of them to be very productive in the language. The aspects of PHP that were intended to make it simple (like pretending types don't exist) actually make it more difficult to reason about precisely. I don't think anyone who knows anything else would ever choose PHP for a fun personal project.

Despite this, there is nothing in PHP that prevents you from doing the thing you want to do, however you want to do it. As projects become larger and involve more time and people, the fine grain of line syntax fades out of view, and all that is left is the large scale design decisions, which are similar in any language. And this is what ultimately determines the technical success or failure of software.

[+] hcarvalhoalves|12 years ago|reply
> People like to argue the superiority of languages, but at the end of the day if the result in PHP is the same as it is in Ruby & Rails, Java, .NET or whatever, does it really make what the language is?

At the end of the day, every program is a stream of bits too. That doesn't diminish the importance of programming languages as a tool for reasoning, managing complexity and avoiding common mistakes.

As the industry shifts from deliver something that sort of works to deliver something with these assured characteristics, programming languages designed around enforcing desired qualities will be of immense value.

> Another good point is the efficiency of a developer working in PHP.

Compared to what? Depends on the developer and problem domain.

> The language is easy, it's so easy to be a PHP master after a few years working in the language.

You can master any language after a few years.

> It's easy to find super-talented PHP developers compared to any other language.

Data?

[+] badclient|12 years ago|reply
Most of the criticism of php seems to contrast it with a language plus a framework. If you really want to compare, compare php with ruby or python, not Django or RoR.

As for php encouraging shitty programming, a good bit of that is that so many more people program in php because its easier to get started with. This does not mean that just because php attracts shitty programmers that it doesn't have more or many awesome programmers than languages such as python.

[+] bowlofpetunias|12 years ago|reply
Methinks the argument that PHP encourages shitty programming has been effectively countered by the amount of crap legacy Ruby code that has appeared several years since Rails became "hip".

It should be quite obvious to anyone by now that when it comes to shitty programming, language is negligible factor once a language has hit the mainstream.

But I'm pretty sure 5 to 10 years from now someone manages to argue that Ruby is crap, Rails is to blame for encouraging a generation of developers to write bloated controllers full of spaghetti code, and that this attracts shitty programmers incapable of understanding software architecture.

[+] jdjb|12 years ago|reply
The linked article explicitly states that the author has found (albeit anecdotally) that good engineers are very very productive in PHP. I've found this myself as long as you don't go writing code that sits in PHP's "hmm, what'll happen if I do this..." area.
[+] lmm|12 years ago|reply
> Most of the criticism of php seems to contrast it with a language plus a framework. If you really want to compare, compare php with ruby or python, not Django or RoR.

Why? What difference does that make as a programmer using it? If another language is more modular, and lets libraries handle things that are baked into php, isn't that a good thing?

> As for php encouraging shitty programming, a good bit of that is that so many more people program in php because its easier to get started with. This does not mean that just because php attracts shitty programmers that it doesn't have more or many awesome programmers than languages such as python.

Maybe not, but it makes it harder to hire the good ones.

[+] Corrado|12 years ago|reply
I think it is fair to contrast PHP with RoR or Django, because it was built specifically for generating HTML. Ruby and Python are general purpose languages that do many more things than generate web pages. No one writes iOS apps in PHP but they do in RubyMotion. No one writes high performance Math routines in PHP but they do in Python.
[+] samuellevy|12 years ago|reply
Before this turns into a recanting of the points in the "PHP is a double-clawed hammer" post again, I would like to remind people that PHP still has a place in the business world that nno other language has stepped up to fill.

http://blog.samuellevy.com/post/41-php-is-the-right-tool-for...

Please stop complaining about how horrible PHP is if you don't use it or have. intentions to replace it.

[+] ryanSrich|12 years ago|reply
I couldn't agree more.

Having worked with clients that publish thousands of articles of content per month the best solution for the job at the end of the day is still WordPress. Have a client that needs an online store? Magento (both of which are built in PHP).

Development shops don't have time to custom build CMS's and eCommerce solution because their clients don't give a shit what language or framework their site is built in.

Show me a CMS built in ruby, python or javascript that comes anywhere near WordPress and I'll gladly switch. Unfortunately it just doesn't exist. Like you said, PHP has its place and until something better comes along stop complaining.

[+] ams6110|12 years ago|reply
I actually feel the same way about "classic" ASP. Yeah, it wasn't pretty. But for simple CRUD pages of the day, it was damn simple and you didn't need ninjas or rockstars to get stuff done.
[+] contingencies|12 years ago|reply
I've used php since v3, in its non-OO days. Coming from perl, that fit nicely. Today, I still avoid OOPHP and continue to write procedurally. The convenience of web-oriented functionality, broad deployment, and soft typing is basically unparalleled, although writing this way requires a bit of discipline. It's also a surprisingly good fit for a lot of server side code if you scale beyond a merely web-based execution model and have existing libraries. These days, I generally avoid perl if data structures are required, and despite dabbling RoR-esque frameworks feel overly constraining with regards to execution path control: I don't want a controller and additional layers of abstraction, the web server does that already!
[+] goshx|12 years ago|reply
You just asked for trouble with that last statement lol But I agree, I don't get why people want to force you to do something else, if what you do works fine for you, your productivity and the product you are delivering.

I use php since v3 as well, when I joined College back in 2001, in my first programming class, the professor told me PHP was cr@p when I told him that was the language I was more proficient with. I didn't listen to him... PHP was paying my bills since before I joined the College.

[+] wanderr|12 years ago|reply
Agreed. There are a few things which are stateful and are therefore made easier/better by OO, mainly DB connections. For everything else, we mostly use classes as namespace (pre-5.3) with lots of static methods. In general for backend web it's pretty silly to spend a bunch of time building up stateful objects when your real goal is usually to load up the subset of information the user needs right now, return that and die as quickly as possible.
[+] ChikkaChiChi|12 years ago|reply
Can anyone please point me in the direction of an open source project on Github that can showcase to me the 'elegance' of all these other programming languages that have the scale and adoption of some of the more well-known PHP community pieces?

I feel like so much of the bias towards PHP is either an unfair comparison (language to 'rails') or a bad taste left in the mouth because the person worked with a nasty domain specific language like Wordpress, Drupal, Magento, etc.

PHP is like pop music; there is a lot of it and 'true' artists think it's beneath them. Nevertheless the public demands and craves it, and most of the big web applications that are open source run on PHP.

If you feel like PHP is a blight on the world, by all means go out there and disrupt the community by launching something that gets widespread adoption the way PHP software has.

[+] Corrado|12 years ago|reply
My personal bias against PHP has been born out of every single PHP project that I've encountered has been horrible. Everything from simple one page apps to complex projects has just been an unmaintainable mess.

Several years ago I was told to use Magento on a project. Great, Magento is a mature PHP app and I'll get to see some great PHP code. Nope, I was horrified by what I saw and dreaded coming to work everyday and having to deal with that mess of a system.

I have a hard time getting behind a language that everyone uses but no one uses well.

[+] lmm|12 years ago|reply
> Can anyone please point me in the direction of an open source project on Github that can showcase to me the 'elegance' of all these other programming languages that have the scale and adoption of some of the more well-known PHP community pieces?

Just look at MoinMoin's source and see how much more elegant it is than MediaWiki.

> either an unfair comparison (language to 'rails')

Why is that unfair?

> a bad taste left in the mouth because the person worked with a nasty domain specific language like Wordpress, Drupal, Magento, etc.

If that's how PHP is used in practice then it's fair to complain about PHP.

[+] tomgruner|12 years ago|reply
I don't take php much more seriously than I take pop music. They both exist. At one point in my life I enjoyed them both immensely. Now I have chosen music that better fits my tastes and solutions that better meet my needs.

I don't choose my music by popularity, and won't try point you to popular repositories. You need to look at your needs, and decide what works for those needs. If that is php, that is great. No need to look further. If php doesn't cut it for you, you will have to decide what you need and find a solution that works for that.

[+] gfodor|12 years ago|reply
I feel like the reason you don't see a web app development model that takes from the best ideas from both PHP model and the Rails/Django model is because by the time you've been exposed deeply enough to both of these approaches to truly understand the benefits and flaws of each you are way too cynical and burnt out on the idea of tooling around building "the next big web framework." Instead, after watching trends come and go, you just take whatever you can get for free and go out and solve real problems with it.
[+] mVChr|12 years ago|reply
I'm preferentially a Python programmer who is currently working on a large well-known high-Alexa-ranked website that uses the LAMP stack. The site has been around for a while and is a behemoth, so I understand why it has stayed with these technologies despite the fact that there are many people on the project at this point who'd prefer otherwise. There are both ugly workarounds and rambling boilerplate in several places due to limitations in both PHP and MySQL, and there are also other ugly portions of the codebase due to inexperienced developers or bad legacy decisions that haven't been fully refactored (not the fault of PHP or MySQL). However, there is also a good deal of work that is well thought out and architected so I no longer have as many qualms about PHP as I used to (that I now realize was due to being thrown into codebases that were just a mishmash of crap... there do seem to be more of those in PHP than in other languages, but that's just my personal exposure).

All the same, if you're not inheriting a legacy codebase, I don't think there is any reason to use a LAMP stack on a greenfield project that you will be creating tomorrow. There are just too many better alternatives out there.

[+] sil3ntmac|12 years ago|reply

    > Facebook’s PHP Codebase
    >  x * 105 files
    > y*107 LoC
    >  10 releases per week
    >  Anecdotally, good engineers are astonishingly productive in PHP
Erm... are you kidding me? LoC != productivity, not even close. And it goes downhill from there :( I really, really don't want to rail on PHP (people do that enough, it gets old, yada yada), but you're kinda asking for it here. The only useful point made is about state, although that's a double edged sword.

...Fuck it, I'll rail. It's 2013. Do yourself a favor. Use something better than a horribly inconsistent glorified cgi script.

[+] Joeri|12 years ago|reply
That's a very unfavorable reading of that slide. Who are you to say they are wrong when they talk about their own anecdotal experience?

Speaking anecdotally, I got exposed to PHP before I did to Python. I tried Python after hearing how much more amazing than PHP it was. I understand why people say that now, because Python has a "flavor" that I suspect most programmers find more pleasing. I also learned another thing: I am not more productive in Python than PHP.

PHP, like JavaScript, is a language constructed out of good parts and bad parts. They both suffer from the same ailments. It is painfully easy to construct code examples of their horribleness, there are mountains of bad code floating around the internet, they lack essential facilities like strict typing, many facilities that they do provide should be carefully avoided, and the overall flavor of the language is just plain weird. However, PHP, like JavaScript, allows you to be remarkably productive.

JavaScript got out of the doghouse when Douglas Crockford wrote his book and converted the JS community to the jslint style of programming. JavaScript didn't change, but the perception and practice of it did. I think PHP needs a similar champion who is willing to say: PHP can be a good and proper language, provided you use it correctly, and btw here is a tool that tells you whether you're doing that in your code.

I am a PHP programmer, and to your high and mighty attitude I say: screw that. There's nothing wrong with being a PHP programmer.

[+] fsniper|12 years ago|reply
Please don't flame war. If you do not like PHP do not use it. Don't force another language to someone else's throat.
[+] shire|12 years ago|reply
Idk about you guys but I love PHP. After using new technology for Web Development PHP makes me feel nostalgic. I really enjoy PHP's ease of learning for Web Development. It's easy to understand Databases and Server-side programming using PHP than it is using Ruby on Rails, IMO It feels like magic using Ruby on Rails.
[+] dribnet|12 years ago|reply
This was an interesting talk. My own interpretation was that PHP's strengths were claimed to be:

1) State => because endpoints have no persistent state

2) Concurrency => because there is no concurrency model

3) Transparency => (1) + (2) + fast reload = easy to understand

These combined give the language nice programmer "ergonomics" (Keith's terminology). It also limits the collateral damage any particular change to the codebase can have which allows Facebook to more confidently deploy multiple times a week.

[+] Joeri|12 years ago|reply
I think PHP's strength is that the default way of how sessions work makes you intuitively build shared-nothing architectures that parallellize easily and have session data that is hard to corrupt. Sessions are locked at the beginning of the request, and the changes are committed atomically at the end of the request. The next request by the same user is blocked until the session is unlocked. This means that any error causes a rollback to the last known valid session state, and that it is basically impossible to have concurrency bugs (though obviously a PHP server can handle more than one request at a time if they're coming from muliple user sessions). A PHP app that gets an error will typically recover just by pressing F5, whereas in other platforms often you have to log out to throw away corrupted session data. I had little appreciation for this myself until the PHP app I work on reached the point where it had both a large codebase and a large userbase.

Remember also that a large part of the reason why facebook won over its competitors (friendster and myspace) was technology. Both myspace and friendster had trouble scaling up their featureset at the same time as their userbase, whereas facebook pulled it off relatively well. It's hard to know without inside knowledge whether PHP had anything to do with that, but it obviously didn't prevent facebook from winning.

[+] ihsw|12 years ago|reply
Indeed, there's something to be said about shared-nothing. Lua takes the cake in that since it can be so easily fit into so many nooks and crannies.
[+] Xorlev|12 years ago|reply
It's a strange, strange world when your code has more gravity than the language it's written in and you start warping your language to fit your view of it.

I'll be the first one to take a swing at PHP, but Facebook has done some awesome things with it. I used to program in PHP and it does have some really nice bits...I mean, it's hard to fathom not waiting for my container to start anymore and go back to the days of save/reloading.

Cool. Nice link, OP.

[+] maerF0x0|12 years ago|reply
I like the look of this "hack". It adds things to PHP that I missed from C# .. now if they will add Accessors syntax, that would be nice, especially for those that use Doctrine2. PHP is as professional of a language as the user. I found fun working with PHP, C#, (node)js, python and think each has its own way, quirks and benefits.
[+] Joeri|12 years ago|reply
You can easily add something like accessors using traits. I cooked this up in 5 minutes: https://gist.github.com/jsebrech/6740010

You can do a lot with meta-programming in PHP. For example, you can write your own array type if you are so inclined and use it anywhere you would use an array. Here's an experimental library that showcases the meta-programming abilities: https://github.com/jsebrech/php-o

[+] dancecodes|12 years ago|reply
PHP must be more functional and use concepts of Functional Programming but without lost current features.
[+] vinight|12 years ago|reply
obligatory X is better than php flames on the way.. php just works.. end of story
[+] jrockway|12 years ago|reply
PHP just works... if you're willing to spend more time on it, find more bugs in production, have a less readable, extensible, and maintainable codebase, and have no taste.

PHP is the dream of a one-man team that gets paid by the hour. Get contract, slap something together that makes the client willing to pay, throw it all away and do it again when the client wants a change.

[+] harshreality|12 years ago|reply

  $productid = "0x4zz5";
  print $productid + 4;
If printing "8" is your idea of a working interpretation of that code, then PHP is the language for you.

If not, then PHP doesn't work. End of story.

[+] dancecodes|12 years ago|reply
dont see any PHP Seriously.

Its just baby garden. Im sorry.

PHP will be Seriously if will use major Erlang features: processes, pattern matching, atoms, lists, tuples

[+] krapp|12 years ago|reply
So what you're saying is... the language that's holding about 80% of the web together isn't worth taking seriously... because it isn't Erlang? Remind me how many sites are built in Erlang again? Why would lists and tuples be critical in generating html files?
[+] hayksaakian|12 years ago|reply
> mysql_escape_string vs. (sigh ) mysql_real_escape_string

ouch

[+] bilalq|12 years ago|reply
I don't think bringing up deprecated functions is valid criticism. Everyone uses PDO these days.