PHP Sucks, But It Doesn't Matter

Here's a list of every function beginning with the letter "A" in the PHP function index:


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2008/05/php-sucks-but-it-doesnt-matter.html
1 Like

PHP sucks is incredible misinformed. Any language can be considered to suck if it’s being written by a programmer who sucks. Yes, the functions are doubled in cases and yes, the parameter lists are annoying at times, but PHP can be just as elegant as any other language, if not more, if a good programmer is writing the code.

Furthermore, compare its execution speed with any of its competitors and I’d bet for PHP more often than not.

I used to be a C# programmer and I have found that with PHP, I am far more productive, I enjoy my programming time significantly more, and my applications are more elegant. Obviously this is subjective, but isn’t part of the point of programming to enjoy it, to create elegant solutions, and be productive?

Anyway, that’s my 2 cents.

1 Like

Don’t mix-up bad programmers with a bad language, most PHP code out the looks crappy and ugly because of bad programmers. It is totally possible to make good working beautiful coded applications where code, data and context is separated.

PHP is as good as C and almost as forgiving, this means that the programmer needs to put more discipline into short, readable and good commented code.

I’m surprised that the dollar sign thing in PHP doesn’t get critique. Every single time Python is mentioned to an audience, who likely have no idea what it is, the use of white space is mentioned as if some kind of original sin that makes whole language impure. I honestly can’t understand how anyone with experience from any other language can stand PHP’s requirement to use dollar signs to tell the interpreter that the next thing is a variable.
Couldn’t the original language designer bother to read a book about compilers and just threw something together?

No offense meant to PHP users. I know that after a while things like typing $ becomes automatic and there is something to be said about having absolutely no restrictions (types, include files, namespaces etc.). If you are really good programmer, you can do good code without any boilerplate. Unfortunately most programmers are not that good.

Jeff, did you let Reg write this entry without telling us? Next thing you’ll be all “blurb this” and “blurb that”.

At least you got one thing right “… But It Doesn’t Matter”. I’d like to let everyone know that at least 70% of the web related programming jobs out there will have you working with PHP, most likely using a LAMP stack. If you’d like job security, knowing PHP is pretty handy as it is the standard for web application development.

The PHP Team understands the problems with the language, the advances being made in frameworks, unit testing and the mass conversion from the bastardized OO in 4 to mostly better OO in 5 are mitigating those issues.

The article completely missing the point of PHP: ease of exploratory web development and deployment.

With mod_php, which is widely available even in most basic ISP hosting plans, developing php is like writing html pages, no additional set up necessary, unlike fastcgi/scgi/app servers required by other languages. Deployment is simple as well, just copy the code directory over and you’re done. Rails is simple to development but a bitch to deploy with various additional required components to choose/setup. The mod_php model also ensures no memory leaks due to PHP scripts. PHP scales because apache/mod_php scales.

The flat namespace and ill thought out libraries of php are ugly, but with the search function of php.net and the helpful comments, nothing can’t be worked around quickly.

Until language elitists figure this out. PHP will be the dominant webapp language for a very long time.

Yada, yada, yada, all words. Since PHP is considered by some easier less verbose than C# then put your money where your mouth is by solving the problem below cleanly elegantly:

For this XML:

( http://today.java.net/pub/a/today/2004/08/12/groovyxml.html )

I want to get totals for accounts “a” and “b” and then store everything into a strongly-typed collection or list of objects (or failing that hashtable / dictionary). So basically I want:

id = “a”, total = 1700
id = “b” total = 3400

In C# the solution comprises one line, try to replicate that in 1 line or less:

from account in xDoc.Descendants(“account”)
group account by account.Attribute(“id”) into accountGroup
select new
{
id = accountGroup.Key.Value,
total = accountGroup.Elements(“transaction”).Sum(t = (int)t.Attribute(“amount”))
};

Anybody up for a challenge ?

@Bloodboiler
The “$” prefix on PHP variables actually does have a purpose. It allows the developer to embed variables directly in strings rather than by using a substitution function (either explicitly or implicitly) such that rather than having:
print(‘You are running {0}, on {1}.’, sApp, sOS);
or
echo 'You are running ’ . $App . ', on ’ . $OS . ‘.’;

you can just have:
echo ‘You are running $App, on $OS.’;

Which one is the easiest to read?

Was it not the great Bjarne Stroustrup that said:

"There are only two types of programming language:

The type everyone complains about.

The type nobody uses or cares about."

I think that you can judge for yourself, based on the amount of b*thcing about PHP, into which of these PHP falls.

“This article is offensive in its naivety. Your gripe here isn’t that PHP sucks, but rather that you suck at PHP. They are vastly different concepts.”

Hehe… good one dude. What I got from the blog is more like “everybody sucks at PHP and it’s ruining the language because the sucky features that sucky programmers seem to like (and good programmers hate) is all being rolled into the core language.”

This can happen to any language: VB being the prime example. There is nothing fundamentally wrong with VB depending on who you ask. For the most part it is just a programming language. The preponderance of bad VB being set up as “example code” and the developers who aren’t good enough to see that the example is bad code, and used it in droves all over the place, caused VB to evolve into a bad code space to be working in.

That is the problem with PHP - not that it’s a bad language, or that it’s hard to learn or anything. It’s that when you adopt PHP, you also get it’s whole extended family of crap code, and the crap code that survives long enough seems to be happily folded into the main project as a new function. This is a bad ecosystem to be living in. Survival of the fittest may not be working correctly in the PHP world - and that makes it a bad environment to work in - IF you choose to use the built-in stuff. And if you choose not to use the built-in stuff, then you might as well not use PHP, because it’s not much of a language by itself - it’s the built-in framework that makes it useful on web sites. And I’m sure there is considerable disagreement over whether functions like a special regex-based substring should be folded into the main project or not.

There’s a bunch of reasons why I think those functions should NOT be part of PHP - the main one being what someone else touched on - that it gives me an incentive to not write my own version of the function, and there is no way to choose a different library for that function, or eliminate libraries to make it leaner. You get all the weird functions or you get nothing - not even the language itself.

Let us just start with the old ‘its got to many functions’ - they may have thrown everything into the toolbox without thinking if it should be in there, but the fact is you do not need to use them, and I probably only use less than 5% of them in a normal day.

One of PHP’s greatest advantages and disadvantages is it’s simplicity. It allows any old newbie to knock something together which is great, but it also means a lot of very bad code gets written.

Within a well structured team following strict guidelines it can be a beautiful language, coded badly it can be an absolute mess.

I have been programming since the days of BASIC + Assembler (6502,65186) and I have tried most things over the years and always strive for simplicity + the ability to build structured complexity. PHP is the most fit-for-purpose language in the web 2.0 space giving a fine balance between quick to build and scalable given time (and lots of extra’s)

Whoah, so many comments.

I liked php when I did it. It was way better than (classic) ASP being far more expressive and easy to use framework. It also had a wicked searchable online reference with decent examples to help you get up and running. The quality of MSDN still isn’t always on par for how good that online help was.

Sure the name of some methods suck, but really, if they wanted to change that, they could. You get used to these things.

I think the benefit of compiled languages like C# are the fact that they work better in large teams. There’s also a lot of benefit to catching errors at compile time. Stuff like ASP.Net does integrate better into a windows infrastructure. Let’s face it, there’s a lot of windows infrastructure out there.

Popularity doesn’t mean it was done well at the start, but popularity means everyone knows it (and probably hate it to a degree). But it gets the job done in the end, and no methodology gaurantees that, no matter how pretty or perfect it is. Like windows, it’s not the best, but it sure is popular.

Seriously, C# is great, but sometimes I get the feeling that there are too many teams in MS pushing too many technologies. My brain can’t keep up. I should become a manager I guess.

All languages are collections of arbitrary stuff borrowed from other languages. And arguing about how pretty one language vs. another one is like arguing about which language you should use to write a recipe for a cake.

PHP is an interpreted language. That alone should make you want to use another language.

Well, really, PHP 4 sucks, and PHP 5 isn’t all that bad. The PHP 5 object system is pretty decent, and PDO (which is available for PHP 5 and standard with PHP 5.1) is a decent way of accessing a database. The problem is that almost all PHP code in existence is PHP 4, and the PHP developers I know are hardly aware of PHP 5 features, mostly because their hosting companies haven’t upgraded yet.

-Max

Like others have said, crappy code can be written in any language. PHP just has such an unusually low barrier-to-entry for new programmers that you end up with a lot of people slinging around crappy code.

I’ve seen some absolutely brilliant engineering done in PHP. There’s plenty of modern software constructs available in the language, and plenty of frameworks are available if you really want to make your solutions clean.

I’ve heard all the arguments before, and like you say Jeff, they really don’t matter. When I started coding in C I was constantly looking up library function names and parameter lists, even though they were all logically consistent. Even though you can argue that PHP’s function names aren’t consistent, that’s relatively unimportant to experienced programmers who have most of the commonly used functions and their parameter lists memorized. Not to mention that the manual is fantastic.

“no sensible framework baked into overall product”

Why on earth should a framework be baked into a language and thrust upon you? Separating your framework from your language should be a language designer’s primary goal, not something to be avoided…

i couldn’t disagree with you more Jeff. php, as a language is easy and sensible. there are a LOT of library functions, but you’re making the wrong comparison. if you put php side-by-side with VB + .NET, you’ll find that php does what a web developer needs and is simpler and more efficient. i’ve used both, and will use both again (though i lean more towards c# in the M$ world), but my preference is for php.

Also, it might be interesting to do an article on how almost every “X Language Sucks” article or comment in the world is written by people who have never used X Language extensively, or by people who don’t have a good understanding of the features of X Language, or by people who have only used one language and think that any language that works differently automatically sucks.

When I was discussing alternatives to Perl with people, the defenders of Perl were uniformly people who didn’t have extensive experience with any other language. Defenders of PHP 4 are often the same–they don’t know anything about any other language because they don’t have to–PHP is so popular that they could program in it for the rest of their lives and never see another language. I’m not saying that either of those languages suck–they have their uses. I’m just pointing out that it’s interesting that most of the arguers in this field–on either side–are uninformed.

-Max

Very good article!.. I agree, PHP may have its downfalls, but all can be resolved with good coding practices, and future releases. The same thing has happened with dozens of other “non-professional” languages. Also, PHP is easy to configure and install, regardless of the machine it is on, and all of its weaknesses are well-documented, with work-arounds readily available to everyone. Also, I think an environment where you can make mistakes will teach you not to make them more effectively than one where mistakes are impossible, or unlikely.

To use an analogy:
Fancy running shoes won’t make you a sprinter, the best ingredients in the world won’t make you a chef and world-class paints and paintbrushes won’t make you an artist… only hard work, practice, patience and some talent can.

I’ve always thought that learning how to program is more important than learning a particular language, or how to use a particular editor.