PHP Sucks, But It Doesn't Matter

If in any language one can write beautiful code (with that I agree 100%) I wonder what makes some laguages produce sphagetti and others lead to good code… For instance PHP and Perl tend to be maintenance nightmare, while Java and Python source code is much more maintainable.

  • is it low entry barrier? (Perl has high barrier to entry)
  • or too fast learning curve? (python is quick to learn)
  • or maybe standard libraries influence programmers (but Java had an old collections framework that was ugly but that didn’t pollute programmers’ minds worldwide)

What is the reason most successful frameworks like JUnit, Spring, Hibernate happen in Java world first before being ported to .NET, Ruby, Python, PHP? Is it that majority of experts and creative people do mainly Java? Or perhaps there is something in the language that stops developers from bad practices and enforces them to seek for better solutions? Or in problem space they deal with? Or perhaps in the platform, or in the ecosystem around given language? Or in books that people start learning the language from?

So, which of these you think contain core root of the problem?

There are a lot of upcoming new languages like Groovy, Scala etc, what should focus their creators on to minimalize the risk of them evolving to another maintenance nightmare? Perhaps it would be easaier to anser “opposite” question: how to design a bad language that will result in tons of mess?

It’s worth pointing out that in addition to some of the other big names mentioned above, Yahoo! also standardized on PHP some years back, and, as far as I understand, many of their properties have been built using it.

The unfortunate fact of the matter is is that PHP is that is virtually on every server in the world. Why? Because its really easy to deploy with no hassle. This means that PHP is not going away anytime soon.

While I agree PHP is … crappy (to be nice :slight_smile: … it has its ups in that the time to market for php code is extremely fast. In the past couple of weeks, I’ve made quick apps that work just fine with PHP. I would never create a large scale app with it, but for quick and dirty things, it’s pretty ideal.

The unfortunate fact of the matter is is that PHP is that is virtually on every server in the world. Why? Because its really easy to deploy with no hassle. This means that PHP is not going away anytime soon.

While I agree PHP is … crappy (to be nice :slight_smile: … it has its ups in that the time to market for php code is extremely fast. In the past couple of weeks, I’ve made quick apps that work just fine with PHP. I would never create a large scale app with it, but for quick and dirty things, it’s pretty ideal.

There are two egregious logical fallacies in your argument. First, by attempting to use facts to make a case for the languages goodness or badness, you commit a naturalistic fallacy. PHP doesn’t suck because it allows you to write function names in three different ways. It does not suck because you consider it ungraceful. It does not suck because crappy coders use it. By the same token, it does not rock because its used by some of the biggest web properties.

Secondly and to a lesser extent, you’ve got a “post hoc ergo propter hoc” (after this, therefore because of this). Just because you used what some consider to be crappy languages in the past, does not validate what you are saying now about PHP. While I can understand and appreciate the effort to “commiserate,” I fell it is expressed under false pretenses.

Plus, to be perfectly honest, we PHP developers don’t need it. I find PHP to be a tremendously effective language, blending all the useful parts of C, C++, Java, and Perl (which also contributes to its hodgepodge nature) to tackle the monster that is the web. I have no trouble reading it, but then again I build on the platform professionally, full-time, and write in an excessively clean fashion.

The lack of concrete evidence to support your argument, and the overriding presence of pure opinion-based references, makes your argument look like nothing more than fanboy ranting. If you’re interested, I’ll have a post up on my own blog to counter your arguments pertaining to the language’s utility later this week.

This is two posts now where I think you’ve gone off the rails, Jeff. I hope you won’t make a habit of this. :wink:

Without reading all the other comments, and as a long time PHPer, let me first agree that PHP is messy. The reason I got into PHP was the low entry barrier. It is not a disciplined language. It’s very easy to get started and thus you can find a bunch of junk code and duct-tape solutions.

But in that same stroke, getting good at PHP actually requires discipline. I’m not claiming to be a PHP guru, but I’ve written many, many enterprise-level web apps that have stood the test of time and that have helped many, many people. I spent time studying “good” programming practices from other languages and did my best to apply them to PHP. And it worked pretty well.

PHP is powerful and can do a lot, but that doesn’t distinguish it from other languages. In fact, nothing does - shy of it running some of the most popular sites on the internet. But again, I would suggest that choice was made due to the availability (and free-ness) of PHP. It’s a very low overhead language.

But I suppose in the end, what’s it matter? I know it sounds like a cop out excuse, but ASP, PHP, Java…they’re all just tools. Thing is that if it were not for file extensions, we wouldn’t know what any web site/app uses.

I’ve made a nice living working PHP magic. If you actually take PHP beyond downloading and installing pre-fab software, it’s extremely handy. But since it doesn’t force you to learn proper programming methods, you actually have to learn them and understand them. Something you might not get from IDE and languages that do it for you.

Jeff - I’m having a hard time agreeing with you. I have several reasons - but keep in mind that I have limited .NET experience (I’ve never taken the time to learn it/use it)

I agree that PHP feels like a hodgepodge of functions that have been pieced together. However…
A couple of years back, I was using the (choirs of voices in the background) all-powerful Java language to code a website. The use of beans was pretty cool and I enjoyed basically having the full power of Java at my fingertips. That was when a funny thing happened. I had to handle a file upload. OMG!!! JSP had no default means to handle a simple multipart/form-data submission. I had to build a whole crap-load of header-parsing nightmare just so my users could upload a stinkin’ image. What a pain. Arrays? What a joke. An array could have an int as an index but not an Integer? (they are different, of course) - 1 is not the same as 1 in Java, I suppose.

So I learned to hate Java pretty quickly. I eventually wrote version 2 of the app in PHP. My file upload problem was solved with the global $_FILES collection without any extra coding. Arrays could be associative with the same array() function and I could sort and all that.

For some reason, PHP just feels like it was made for the web…and only for the web. Java and .NET are like hybrids that allow me to write a web app or a windows app with the same language.

I can use a screwdriver to put in a screw and the handle to pound in a nail; but shouldn’t I just use a hammer for the nail?
/bad_metaphor

One point that struck me when I read this article was:

You’ve probably heard that sufficiently incompetent coders can write
FORTRAN in any language. It’s true. But the converse is also true:
sufficiently talented coders can write great applications in
terrible languages, too. It’s a painful lesson, but an important one.

Seeing how these successfully and functional these large projects have been, it’s important to look higher than the language it was implemented in. When I see Wikipedia, I think of the immense contribution of data and knowledge, not the PHP scripts that power them.

On the other hand, for aspiring software engineers, it’s more important to choose the cleanest and most maintainable approach to making the next useful app. Just because other successful projects have used PHP, doesn’t mean that PHP is a good choice to build with. This also applies to whatever language is in vogue at the moment. A designer should choose a framework like Ruby on Rails for it’s technical merits rather than the hype around it.

PHP always reminded me a lot of classic ASP.net… not structured as well, but the way it worked and made a mess of spagetti code. ASP thankfully evolved into ASP.net, PHP is still PHP.

I’ve got to think it’s wildly popular because it’s really the best option you have for sites using Unix. You don’t see very many Windows developers using PHP.

Let’s at least agree that it’s a step up from using Perl to create interactive websites.

I meant to say “PHP always reminded me a lot of classic ASP” in that comment… not sure why I tacked .Net onto the end of it. Oops.

I don’t usually comment on your blog, but I read them every chance I get. Anyways, I code professionally in C# and VB.net, but I use PHP every chance I get for personal projects. Why? Because, PHP is streamlined for the web and has built-in functions for just about anything I can think of to make building a dynamic website easier.

I’m able to get a nice, cleanly written, fast and functional PHP built site in half the time that it takes me to do the same in C# and .NET. Combine PHP with Apache and MySQL and I haven’t found anything I like better.

I don’t think you can say the language sucks when so many of the best biggest sites on the web run on it. You can say the programmer sucks though. I look back at PHP code I wrote 5 years ago and its a mess, but today I follow a lot of structure to my code and feel that its just as managable as anything I’ve written in C#.

I have a Halo 3 Multiplayer stats website, http://halocharts.com, that is written in PHP that’s getting over 3000 unique people a day and tracking over 50,000 players. It would have taken me months longer to write the same site in C# and SQL Server, plus all of the licensing fees would have been a pain…

I see PHP as a language that allows choice. I started with PHP out of necessity to get a job done. It was either PHP or ASP, and I was leaning toward ASP except I could find absolutely NO documentation on the net for ASP at the time, but more than enough for PHP.

PHP also let me choose my OS and my web server platform, which ASP did not. I’m a big proponent of choice.

You’re right. I can code spaghetti code really quickly in PHP but I don’t have to. The language let’s me choose my programming style. I can (since PHP 5) go the object oriented route or complete procedural if I want. I can code sloppily or code extremely cleanly – it depends on me. The function_list_that_goes_on_forever seems to be the same as the namespace.that.goes.on.forever, just a different convention.

It’s choice. I’m grateful I have it to make. I choose to code responsibly and be wise in my coding convention, commenting and holding to an overall convention. If other people do not, then they’ve made that choice.

I think most people forget the Human Factor. The #1 reason IMHO that php is so popular is because it brings the productivity to the human side. In Java and other older languages, you have to learn one of the bazillions of frameworks out there and hope that the framework does what you want. When you remove that factor, the speed that a developer can code (without errors of course) is linearly proportional to the speed he gets new features out. You want more features, just have to type faster! Haha!

Developers feel better if they think that the bottleneck of productivity is on their side, ie, one only needs to transcribe mental ideas to code to create new stuff, instead of having to learn some new API in an unfamiliar framework just to produce a Hello World. The problem is, not everyone is brilliant and almost everyone creates bad code. The difference between php and say java is that some of the components of an app (db acess, controllers, etc) are already solved out in a reasonably way for you if you use some framework.

IMHO frameworks like rails or grails managed to balance the needs of most common web app aplications into the framework itself, so that the developer effectively gets things done with minimum effort.

As for the maintainability myth, my view is that maintanability is much more design/architecture related than language related. Code aArchitectures normally don’t scale in the sense that adding new functionality becomes more and more harder, instead of being a constant value.

My .2 €

I tend to like programming languages that everybody else complains about, like C++, Perl, Javascript, Visual Basic, and PHP.

All of those languages can be ugly, all can have weaknesses, all have some bad design here and there.

But they all work, they all get the job done, and all are in widespread usage.

I agree with another poster, who put it very well - comparing these so called “ugly” languages to great cities like New York, Paris, and London. Those cities have dark underbellies, and rift-raft, and crime and poverty, and so on. But they’re great cities that are homes to millions of people, and are visited by millions, and are exciting. Then the other poster compared more “pure” languages, like Java, C#, Python, etc, to works of art - very beautiful, but limited in usefulness.

Anyway, I love PHP. It’s fun, easy, productive, flexible, powerful, efficient (for an interpreted language), and extremely useful. PHP, much like C++ and Perl, can be really ugly. But also like C++ and Perl, it’s extremely useful.

To solve real world programming problems, I’ll take utility over beauty any day.

Besides, PHP has scoreboard - Yahoo, Facebook, Tiobe, Wikipedia, YouTube, Word Press, Sugar CRM, and so on. A language that truly “sucks” simply can’t produce great web apps like that. A language that is perhaps ugly, but useful, does.

The great thing about PHP is its freedom. Professionals can use it in a growing industry, as well as “script kiddies” can use it in their mom’s basement.

The structure and maintainability of the code is largely dependent and determined by the skill of the programmer. The way it should be…?

I am personally tired of hearing Microsoft fanboys denounce the PHP language for flaws that it had in version 4. Maybe you haven’t checked in sometime, but version 5 is now out in production.

“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.”

Wow, ignorance is bliss. I don’t think you are qualified to come up with statements like this when you say you are a Visual Basic programmer. I have programmed in Visual Basic before, and I thought I was losing intelligence throughout the entire experience. A Visual Basic programmer, is a lazy, ill-informed programmer. That’s just my two cents anyway.

I could be partially biased however, because I work with a VB programmer, and he doesn’t know how to “write” code. He copies C, C++, and C# scripts from the internet, and runs them through a X to VB converter. Obviously that makes some pretty (sarcasm) code. :wink:

So your argument is, essentially, that PHP is OK, because all the cool kids are using it?

Saying “results are what matters” is like saying “we should kill our current set of politicians and lobbyists to deal with economic, oil shortage, food shortage and global warming problems.”

And by the way, your sense of humor about PHP? It sucks.

And arriving to the conclusion that PHP sucks on the quality of code written by anonymous? It’s hardly fair to a language that can be easily picked up by beginners.

What would be interesting to know is how well does an average person without programming experience picks up any language within a time constraint.

Why is a language bad? The worst crap I’ve seen many times was in the revered C++. Some of my best code in college was in Fortran, for crunching numbers. The Paradox Application Language (PAL) for DOS was completely logical and stylish.

Perhaps we judge a language based on the (pseudo) framework it’s used in? I despise .NET Master pages and the mangling that occurs when the page is assembled and my viewstate is mis-placed. Case sensitive languages are retarded. Ruby is good but Merb is a better framework than Rails?

In the end it’s what @monsur referred to as low “impedance mismatch”, then it’s the reliability, maintainability, etc., that the language offers.

100% agreed. I started with assembly, moved to C then C++, then to Perl and Java (per for quick CGI and Java for “real apps”. I woudn’t touch “Personal Home Page” for anything.

About 4 years ago I changed my mind, and for exactly one reason: every commercial hosting account you can get - from $1.99 / month up, supports PHP.

I think the whole argument here makes a very big mistake! It mixes language and API. So do most articles you quoted or linked to.

This is a big mistake most people usually do with Java.

int i = 10;
String s = “Hello World”;
Object o = new Object();
float[] farray = new float[20];

This is language.

ArrayList ar = new ArrayList(20);
Iterator it = ar.iterator();
JPanel jp = new JPanel();
jp.getContentPane().add(new JLabel(“Hello World”));

This is not! This is API.

PHP as a language is very clean, has very little elements. It defines a couple of data types, primitive operation on them (add, sub, mul, div, and, or, xor, etc.), it declares functions, it declares objects, arrays and hashes.

The huge amount of functions, with inconsistent namings and unexpected behaviors because two similar functions might have entirely different behavior, these are all API. They are the default API, that means they are there on a fresh PHP installation without installing any plugins; but they are not really part of the language itself.

I admit, while it is very clear what is language and what not for other languages like Java or Perl (because this is documented), the borders are pretty blurred for PHP. However, PHP is not the only language where the borders are so blurred. Another familiar one, and probably mostly used language in computer technology today, is C. E.g. this is langua in C:

char * buffer = calloc(sizof(char), 100);

But C does not guarantee int’s to be 32 Bit, so programmers like to go there and do

u_int32_t num = 10;

or

uint32_t num = 10;

and when you want to open a socket (for network data transfer), they do:

int so = socket(AF_INET, SOCK_STREAM, 0);

However, this is all not language. No C compiler in the world needs to successfully compile that. u_int32_t is actually nothing at all (where the heck does this come from? Only because it’s there on most system doesn’t mean it has a right to exist). The only thing the C standard specifies is int32_t, that is signed, not unsigned. uint32_t is defined in the POSIX Standard, but not every platform that supports C needs to support POSIX (many don’t support POSIX). And the socket function is also only defined in POSIX. Linux is mainly POSIX compatible, so is MacOS X, but Windows for example is far away from being POSIX compliant.

Long post, short summary:
It’s not PHP that sucks here, it’s the default API of PHP that sucks, because of all the negative issues quoted or reported on other pages.