PHP Sucks, But It Doesn't Matter

I’ve written about 200k lines of php in the last year. I’ve also written a huge amount of VB.NET and C# too. I find that the largest difference is that php will let you do what you want to, ugly or clean, whereas the others tend to guide you toward cleaner code. You can be clean with php, you’re just not going to learn it from online tutorial sites. OO only really came with PHP5, so most of the stuff out there - even though 5 has been out awhile now - hasn’t really been moved over. The frameworks are nice, and can really help, but often times it feels like you’re just bring out a bigger sledge hammer.

“And does this also mean that HTML and SQL arent any good?”

Actually… it does! SQL is a curse for computer science, huge legacy of bad choices both from the semantic and the syntactic point of view. It would take me too many words to explain why SQL is a bad programming language.

HTML took forever to decide if it was a language to describe the structure of a document or its aspect, it’s full of legacy tags that nobody uses nor knows what they were for. Add CSS and JS to the mix and you get something that nobody fully implements, nor understands.

Smells like a troll.

“If you sit down to program in PHP and have even an ounce of programming talent in your entire body, there’s no possible way to draw any other conclusion. It’s inescapable.”

So the guys that coded all the popular websites you mentionned don’t have an ounce of programming talent ?

You can make bad code with anything.

It lets people actually get the job done and for those who pay the bills that’s what matters. While I like the concept of logical syntax and clean code, working code is what most other people expect. PHP seems to produce results for a lot of people.

“What personally makes me laugh in my mind is how everyone always says how PHP is so badly designed etc., but never can actually show how it slows down their app development.”

Huh? What? Did you not notice the lengthy blog post above the comments section? You might go and read some of the links. Choosing PHP over something else is a choice between money and time. What do you want to spend more of? You must pick one.

Yes, trivial PHP apps can be set up faster than trivial apps in other languages, but trivial apps don’t really mean squat in the real world. I would rather spend two weeks setting up a good environment like ASP.Net, than spend any time debugging a complex PHP application.

Good developers have a ‘spider sense’ for bad code - I can tell bad code from 20 feet away, without even seeing the actual characters. I can sometimes tell bad code without seeing it at all, just by how the app behaves. PHP code is almost always bad code - meaning it’s unstructured, unsafe, incoherent, littered with dependencies, and hard to read. Sure, it’s possible to write good code with PHP, but the properties of the language itself and its community more often result in code that reminds me of “made-up-of-different-stuff-guy” from the Pepsi commercials.

@karl:
Well, it matters in that aspect, that I can take the freely available source code of PHP, strip away all of it’s default API and ship exactly the same language (same syntax, same abilities) with a completely different default library of my own.

Maybe there even exist alternative libraries for PHP already. Perl has plenty of them. Perl has many build-in functions, but also many that are not. If you want to get webpages (HTTP requests) or send e-mails, you don’t use anything from the stardard Perl lib, but you install a custom plugin from CPAN. And here for one and the same task, three different plugins could exist. And if one sucks, why not taking the other one?

I just remember this way too well in Java forums. First people came there and said Java sucks, because with AWT you can’t create usable user interfaces. AWT is just part of the default lib, it is not Java. Then Sun released Swing, which could everything AWT was lacking - and people said Java sucks, because Swing does not look truly native and it’s way slower than AWT. However, IBM has SWT, which is as fast as AWT, needs much less resoures than Swing, still can do almost everything that Swing can do and it looks as native as possible on every platform supported. So, when you use this, does Java then still suck? No… but wait, it’s still the same language, isn’t it? So it actually never sucked. It was the AWT and then Swing API that annoyed people, not the language per se.

Of course you do have some valid points about the language itself in your post.

no closures,

Like many other languages - I don’t see this critical.

no pure OOP

Since when needs a language to be pure OOP to be good? Many are not even OOP at all and many are OOP, but don’t force OOP down your throat. I see no problem with that.

no mixins

See above, I see no problem in that. Since when must languages have that? Actually the wast majority of languages don’t have that. And I don’t think it is good either. It leads to very dirty code and confusion.

namespaces

Yes, that is indeed bad. Namespaces are important. But C has no namespaces either, not even Objective-C on Mac has it (and it’s full OO Support to C in a much cleaner way than C++ does). And in many languages that actually have it, people don’t use it anyway.

horrible scope resolution (you need $this- infront of everything…)

Just like you need “self” in front for Objective-C code. Okay, you wouldn’t need it to access instance variables of the current object, but I think you can use it there as well and it has the advantage that you see it is an instance variable (not one in the current method scope) and also makes sure the instance variable is used, even if there is a variable of the same name in the current scope.

So these are all no killer arguments to call PHP a bad language. All valid, but not killer.

Your main points for calling PHP a bad language choice is its function list and sample code written by others… I am a PHP programmer for my job and by choice on my freelance web projects. I also write in C# but for windows applications only because lets face it ASP and ASP.NET are the slowest choices for web langauges on the net. PHP is fast and easy, like lots of individuals have stated before myself. It is lightweight and with the use of Zend Studio easy to debug.

One might not call the developers on the PHP project of genius stature but one thing you can give them is the rapid pace at bug fixes. I do agree their function naming conventions could use some work, but one can always write useful wrapper classes that use those functions and have your naming conventions.

As you have said before in a previous blog “your code sucks”, and the same is true for PHP code and coders. Most coders do not use good naming conventions and best practices so their code is hard to read and modify. The last time I looked PHP was the most widely used langauge on the web, so you are going to run into more bad code than the others for web projects.

At the end of the day one needs to use the technologies they know and are comfortable working with. So to me instead of throwing it out with not ever really using it, or developing with it on your own I challenge you to do so. That is how I found that I do not like coding in Ruby or even the .net framework for the web not by analyzing from the outside looking in and just saying they are bad languages for the web.

“And does this also mean that HTML and SQL arent any good?”

Actually… it does! SQL is a curse for computer science, huge
legacy of bad choices both from the semantic and the syntactic
point of view. It would take me too many words to explain why SQL
is a bad programming language.

The point of that was to show how the logic is flawed, not that SQL or HTML actually suck. Anyway, SQL is not a programming language. Its designed for getting data out of tables.

“…Add CSS and JS to the mix and you get something that
nobody fully implements, nor understands.”

I think the guy above said it best… everything suck - And at all times. This the human problem we’re facing here, a language problem, which is sliding down the heap from VB to PHP, and now to English

This article should be deleted

youtube is 100% python:

http://highscalability.com/youtube-architecture

Wow,

Fun little article with alot of titty tatty comments underneath…

So let me indulge:

  1. To all the ASP is better because there are more professionals involved people:

Just stop right there. I can show BILLIONS of examples where I work and other places of applications written in .Net something and the code is simply unmaintainable. Don’t even get me started on compiled DLL’s and binary signatured project files… Remember MS is the company that made Ctrl-Alt-Del famous because their OS locked up too much.

If PHP is bad because of all the “ScriptKids” then ASP is bad because of all the “I just read ASP for Dummies and I love drag and drop” n00bs!

  1. For all the PHP nay sayers because its hard to keep PHP clean:

Just stop right there again. Most php books/references will tell you to use notepad simply because they expect you to be a stupid moron who doesn’t know how to torrent Dreamweaver or install Notepad++. Use a real editor, put down the PHP for dummies book, goto to university, learn how to program, learn what it means to “include” something, learn OO programming, rewrite your application, then gives us your 2 cents… maybe we’ll listen.

  1. FFS use SVN when doing a project, its not hard to setup and will help you 53,757 times.

  2. There are just too many “Oh I read dummies books, please let me be a web developer” people out there. Learn how to program from a college first before you go spewing forth ASP spaghetti on the rest of us.

  3. Web Development is not PowerPoint, stop trying pretend like it is.

I love it when people use the infamous array function list as an example of PHP suckage. Sure that’s a huge list, but PHP has better array support than any other language I’ve ever used. You’re just jealous.

The list can get a bit confusing at times, but that’s why PHP has the best online documentation in existence. Don’t know what a function does or need a refresher? http://php.net/functionname.

The few posts above which dared to argue that PHP doesn’t scale are horribly mistaken. First, the front end tier is rarely the source of scaling issues. Second, opcode caching systems such as APC and Zend Platform work remarkably well. Finally, Apache is a huge memory hog and that is often mistaken for a problem with PHP itself. Luckily, PHP runs on lighttpd and many other lightweight web servers.

Last but not least, arguing that “low barrier to entry” is a bad thing sure sounds elitist. You can get a closer shave with a straight edge razor, but do people still use them? No, because in the age of throwaway safety razors they’re impractical.

SimpleTest[1] is a unit testing framework for PHP. It’s growing in popularity in the PHP world, and at least one popular PHP project (Drupal) has adopted it broadly for both core development and many contributed modules.

[1] http://simpletest.org/

"Some function names consist of more than one word. There are three conventions for combining these words:

  1. Glued together: getnumberoffiles
  2. Separated with underscores: get_number_of_files
  3. Camel case: getNumberOfFiles

Most Languages choose one of these variants. PHP uses all of them."

Actually, 1 3 are the same thing as PHP isn’t case sensitive when it comes to function names, it is in other aspects tho, making it suck even more.

Dear Jeff,

I have been an ardent reader of your blog. I have always enjoyed reading you arguing against the common notions of programming, I did believe you are truly a pragmatic programmer as you believed in getting the job done and not care too much about some of the academically approved approaches to solve a problem, something that purists rant much about. But I must say I am extremely disappointed with your disapproval of PHP as a programming language. If you are a truly rational thinker, why cant you justify using a language thats so much more productive in the web environment than any other options we have.
I am quoting from a presentation by rasmus, this is how you parse an Atom data in php

$url = ‘http://www.flickr.com/services/feeds/photos_public.gne’;
foreach(simplexml_load_file($url)-entry as $it) echo $it-content;

Now why would anyone not use it if it has this kind of power ? Since when you have become a language purist, who hates to see functions named rather inconsistently ? After all you are the one who has said that a href=“http://www.codinghorror.com/blog/archives/001062.html” code is not beautiful /a, remember ? , you are the one who said (commenting on joel spolsky inventing a new language for his product) that a href="http://www.codinghorror.com/blog/archives/001022.html"the language does not matter /a.
I thought all you cared about is user experience, and for a language that is designed to work optimally in web environment, if its going to make you super-productive, how is it not good for the end-users ?

Why do you care about how the code looks like ? why do you blame the language for the bad code that not so careful programmers produce ?

I do believe, the reason you are seeing bad php code all over, is due to the fact that php is such an easy language to learn that anyone who might not have any programming experience can jump in and write some code over a weekend.
Are you looking for a language that PREVENTS bad programmers to output bad code ? do you really believe any such language exists ? don’t you think that design/architecture of you application is more significant than the syntax of the language you used to code ?
Come on… give me a rational (and honest) answer, will you ?

The problem with PHP is that almost everyone and anyone can write functions for PHP. For example, there are FIVE functions you can use to replace a substring in a string:

  • str_replace
  • str_ireplace
  • ereg_replace
  • eregi_replace
  • preg_replace

Notice str_replace and str_ireplace vs. ereg_replace vs. ereg_ireplace.

I hate PHP and it drives me crazy because I can never remember exactly how to do everything.

PHP’s saving grace is its ability to be incorporated into HTML. That means you can quickly create a web-based application. Plus, since it is executed on the server site, you don’t have to worry, like you do in JavaScript, whether the user’s browser will be able to execute your code.

I may hate PHP, but it’s what I use when I do my work.

What I find interesting is how infrequently people talk about the maintainability of PHP. I absolutely agree it’s a great language to slap out version 1.0 of your site, as long as you have a really small team and not to complex website.

But once you grow, adding features and developers, the big productivity gains you had quickly disappear. After about a dozen people are working on a PHP app it generally starts to falter in terms of maintainability. Never mind 2-3 versions of features.

Initial productivity is great and speed to market is great. But it’s not everything. When I start a business I expect to last at least several years, so I prepare for that. Sure initially I might have to absorb a little bit more cost, but in the long run it will pay off in spades. If you think speed to market is the end all be all, you might want to watch DHH’s video at: http://www.justin.tv/hackertv/97862/DHH_Talk__Startup_School_2008

One last note, the fact that the language hampers the ability to create functions due to namespacing issues, this tells a lot. Especially as the source and team grows, it really hampers keeping the code clean…

Jeff,

honestly, PHP/VB doesn’tmatterism aside, are you driving mindless traffic to your site with these somewhat outrageous posts (screen touching, then error page with clouds and now PHP)? This site is turning (slowly) to Oprah Magazine of coding-related blogs.

Yes, language design is hard. So is programming. But that does not imply that beautifully designed languages are good for the job. VB is an example of a language that should have never left Redmond labs. I wonder how many developers out there have suffered direct and indirect indignation because of the “cloud of doom” called VB, the rapid dev. environment which broke all rules of OOP, OOD and language design and shed serious doubt to many a developer’s ability to think in OO terms (whether that doubt was justified or not is another matter).

Bottom line: if you don’t like the language (and I also do not fancy PHP), just friggin move on. Power up a C++ compiler, do whatever you have to do. Program in assembler for a while, you will learn to appreciate programming as an art much more after that.

Best,

BugFree

On the subject: a href="http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/"http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts//a

(Summation; certain runaway PHP scripts will NEVER be killed, and there is no obvious graceful way to avoid this. FastCGI would work, I suppose, but neither PHP nor Apache are actually very FastCGI friendly)

People use PHP for the same reason they use Linux; because they are masochists. Why do something simple like run a tiny install program when you can recompile the OS?

“Anyway, SQL is not a programming language. Its designed for getting data out of tables.”

That depends on how you define ‘programming language’.

“I think the guy above said it best… everything suck - And at all times.”

Not true, there are things that most definetly suck less than PHP in many aspects.

@ Mecki:

no closures,

Like many other languages

no pure OOP

Since when needs a language to be pure OOP to be good?

no mixins

See above, I see no problem in that.

So PHP can’t do good OOP, can’t do good Functional Programing and (obviously) can’t do good Logic Programming. Wonderful.

namespaces

Yes, that is indeed bad. Namespaces are important. But C has no namespaces either,

So, we should uniform to a language designed 40 years ago? At least C can be excused because it runs fast.

And in many languages that actually have it, people don’t use it anyway.

That’s not true. If you have them then most libraries use it, user code maybe doesn’t, but you can write bad code even with good languages.

This blog is giving me strange error pages.