Sunday, April 15, 2012

In half-hearted defense of PHP

Okay now there's a big rant about PHP. These things are getting exhausting. I don't particularly like Python, that doesn't mean I have to make any kind of long boring post about it. It's just a matter of my personal preference, and I know that. Plenty of people do plenty of nice things in Python and that's great. Twisted seems like a cool idea. But I don't like Python. And no one cares, and no one should care.


So the rant on PHP has a similar tenor to the ones about Node.js - which already starts us off on the wrong foot. However, as I read through the whole thing, I find that I can't disagree with any one particular point. Every single one seems at least conditionally valid, and at least none of them seem deliberate designed to be maliciously false. So, points to you sir and/or m'am on your post. My rebuttal follows.


I've been using PHP for somewhere around 10 or 15 years or so, and I haven't run into even half of those various weird edge-cases. I'm not saying they don't exist. They seem like they do. But I'm saying you don't run into them so often.


However, I do feel that the long, exhaustive list of 'things that are wrong with PHP' sort-of misses the point. Yes, the language has weird bugaboos about it. All languages do. No, none of them are fatal. The language is easy to pick up and be productive in. It's easy to have a mostly-static site with the odd dynamic page here and there. Deployment is a breeze. FTP up your new files and you're done. You don't even have to think about it. Sites run fast. Development is easy. The documentation is excellent. I haven't seen any other environment that comes remotely close in that regard. Just about any thing you would want to be able to do, there is a function for. It exists to make dynamic web pages, so it fits that well.


The article also rather quickly breezes over an important point. Facebook uses PHP. Why is that? The article states that it's fine for FB because they're huge and can 'engineer around' the various weaknesses of the language. That certainly begs the question as to why they would bother. Is it just legacy? Are they just dumb? I have a hard time believing any of those possibilities.


Mass hosting for websites really only works for PHP. The security gets a little dodgy, but it basically kinda works. Try that with any other webdev environment and you wont get nearly the server-density that you do in PHP. That is pretty hard to beat.


Server-side includes. Anyone remember these? This is really what PHP has supplanted. For that kind of stuff, it's great.


Or for a one-page site. Or a static site that has one dynamic page that does something - you cannot beat PHP.


Plenty of people use it with frameworks for complex sites. If I had a really super complex site to do, I honestly don't know whether or not I'd do it in PHP. But if I did decide to do it there, I wouldn't feel the least bit bad about it.


Edit, reload, etc. You can edit a PHP page on a server, hit reload, and it works. No magic. Or if there is magic in that, it's so magical that you don't need to ever know how it works. This is quite pleasant. No dicking around with production versus development or HUP signals or restart.txt files or any of that shit. On development or production; edit your file, reload. Boom.


Server infrastructure - since PHP is most often served up via Apache, you don't have to throw some kind of reverse proxy in front of it or anything. If you have static assets, they will be quickly served up via Apache's static web-page serving. All for free in the default set-up for PHP.


Performance. PHP is fast. Even without an accelerator. I've built many, many PHP apps, and I've never needed to use one - the database always ends up being the bottleneck, never the web front-end. It will likely outperform most other web environments with no tuning. I *have* had to tweak the maximum number of http processes in Apache on a very high-traffic site, and I've also messed with the maximum PHP memory to permit per-process, but (off the top of my head) those are the only two knobs I've had to twiddle. And I've only had to do that on sites with the highest-of-traffic running on the crappiest-of-server environments.


So if you want to live in your tiny ivory tower and yammer on endlessly on pedantic points about object hierarchies and namespace pollution and function-name consistency, feel free. However, those of us who are jamming out PHP sites will not be doing that - because we will have already finished the project we've worked on and moved on to the next one.

3 comments:

  1. Problem is PHP went the way of Visual Basic, that is, being a very popular language, people has built a lot of crappy apps (as well of loads of wonderful and awesome apps), so it gets a fame of being... crappy.

    So people tends to be elitist and say "PHP is shit and isn't cool anymore", but, ad with every language (and tool), what really is important is how you use it...

    I'm not too much into php, as I'm a sysadmin I'm used to python/bash languages, and I'm partial to the Djando framework, but I don't mind people programming php or myself doing some fast or simple app once in a while.

    You just write your code and in 5 minutes it will be running, every webserver in the world supports PHP out ot the box or with an easy 5 minute install...

    Of course, every of us would love to program pure ASM and make the faster apps in the world... :D

    ReplyDelete
    Replies
    1. Yes - lots and lots of crappy apps have been built in PHP. I might have even built some of them. And, certainly, there is an air of elitism in the PHP-hate.

      I've done a little bit of assembly and while I find it interesting on the one hand - actually doing anything substantial with it is pretty terrifying. Awesome to use a CPU at full speed though :)

      -B.

      Delete
  2. Sinh mổ hay sinh thường tốt hơn ?
    Khám tổng quát ở đâu tốt nhất - bao nhiêu tiền ?rong bài viết này, chúng tôi sẽ giải đáp vấn đề này cho các bạn
    Khám tổng quát gồm những gì giá bao nhiêu ?Sau khi khám lâm sàng xong, bệnh nhân sẽ được các bác sĩ chỉ định thực hiện lần lượt các hạng mục khám bệnh, lấy mẫu bệnh phẩm để thực hiện xét nghiệm.
    Khám tổng quát cho bé bệnh viện nào tốt nhất ở tphcm ?tùy vào bạn có khả năng chi trả bao nhiêu mà Bs sẽ mở rộng hoặc thu hẹp danh sách xét nghiệm.
    Nằm mơ thấy con nhện đen là điềm báo gì?Mơ thấy con nhện là điều khá may mắn, ngay cả khi bạn giết chết nó. Điều đó cũng có nghĩa là tin tốt lành sắp đến với bạn.
    Cách chữa ong đốt hết xưng hiệu quả tại nhàCác bệnh viện nhi luôn phải tiếp nhận các cháu bé bị ong đốt nhiều mũi đã bị tím tái, sốc, trụy tim mạch…
    Bị ong đốt là điềm gì hên hay xui ?Bạn là một người rất tính ngưỡng, khi một việc gì đó xẩy ra với mình, bạn điều muốn biết việc này có điềm gì
    Ong bay vào nhà làm tổ là tốt hay xấu có điềm gì?heo Phong thủy nhà có tổ ong xuất hiện, chứng tỏ môi trường ở nơi bạn sống đang tốt lên vìongđược coi là một con vật mang nhiều dương khí, dương vượng sinh âm nên ong đến thường đem lạiđiềm báo may mắn về tiền
    Chim chết trước cửa nhà là điềm báo gì ?Điển tích này nói về nàng Chiêu Quân, tên thật là Vương Tường, là một cung nữ rất đẹp trong cung vua Hán Nguyên Đế, sau được gả cho vua nước Hung Nô.
    Mèo chết trong nhà là điềm gì – có sao không?Dưới dây là lời giải mã điềm báo khi có mèo lạ hay mèo hoang vào nhà mà các nhà nghiên cứu tâm linh cổ xưa đã ghi chép lại.
    Nằm mơ thấy tượng phật bà quan âm là điềm báo gì?Bà bầu sau khi sinh mổ thường rất đau và kiệt sức do vết thương mổ ở bụng, do đó bà mẹ cần có chế độ ăn uống đặc biệt để cung cấp đầy đủ dinh dưỡng cho mẹ, bé và vết thương ở bụng nhanh lành.

    ReplyDelete