Live data from Hacker News

Ask HN: Why no love for PHP?

news.ycombinator.com

31–40 of 150 posts

Re: Ask HN: Why no love for PHP?

#31

PHP has a few downsides, everything from poor naming conventions to security vulnerabilities. People around these parts are always looking for the cleanest solutions to their problems and the latest methods available. PHP's relative age and problems make it neither. That said, I coded my first startup in PHP. It's dead simple to make a dynamic web page with PHP, but it's also dead simple to create a huge mess. In tha…

Amusing. Rails as the "Dane Cook" of web frameworks pretty much hits the nail on the head. I love Rails but the fanboy culture really sucks.

That reads to me as "Rails is a pop culture icon that only XYZ people know about." I'm not XYZ because I don't know who that is.

Actually, perhaps unintentionally, you still hit the nail on the head.

Re: Ask HN: Why no love for PHP?

#32
I use PHP every day at work. I find that the best way to program PHP is to pretend it is java and ignore (almost) all the other features. Many of the features of the language are very powerful and because they are so powerful, PHP has a tendency not to scale well.

If there are 200+ ways to do one thing you can guarantee that looking at someone else's code will always be an adventure. You CAN write good code in PHP, but it is flexible enough that bad programmers will be able to take it and do much worse things than they could with, say, java.

Call me old hat but I think type safety is an important aspect of scalable projects. If I could add one feature to PHP it would be enforced type safety.

Re: Ask HN: Why no love for PHP?

#33

In the past I've purposefully avoided submitting articles to Hacker News if they were about PHP. I kind of just assumed that they would be downvoted just for being PHP. I wonder if I'm alone in that? Edit: fixed a typo.

If these articles are thought provoking, they could be written about PASCAL and reasonable HN members would upvote it. Someone can be a language snob, but also a computer scientist; computer scientists keep an open mind.

Re: Ask HN: Why no love for PHP?

#34
There are lots of reasons.

* PHP attracts idiots. Partly that's because you don't need to know anything to make simple PHP. So, in the large pool of PHP programmers, there are a ton of idiots. And those idiots produce a lot of verbose code that gets used because it does something. Ruby, Python, Perl, etc. all put up a larger barrier because they don't just come with a session handler or whatnot built in. And that weeds out more of the idiots. Doesn't really have to do with PHP the language, but it is nonetheless significant.

* PHP has a bad type system that leads to errors. There, I said it. The fact that 0 == "string1" and 0 == "string2", but "string1" != "string2" is unacceptably bad.

* PHP has no namespaces. Yeah, they're planned for 5.3, but the implementation is just ugly. This makes it more likely to botch something in a larger project.

* Which leads me to my next point: include/require. In PHP, it's decently common to say require('some_file.php'); and just grab a huge hunk of code. Eww! That code could be doing anything - adding in variables, executing code, etc. While it's true that other languages can do that as well, that's generally not the case - other languages are more in favor of importing objects or functions. Partly it's a language thing, partly it's a culture thing.

* Magic! So, how does mysql_query() know which database to connect to when you don't pass in a database connection? I mean, I'm guessing they're either using a global or if it's in C a static external variable, but PHP is littered with this crap. It's not necessarily bad, but it's magical.

* Functions! So, PHP now has cool object oriented stuff. Still, it doesn't use it at all. I don't object to strlen($var) that much when compared to $var->len(), but there are other cases where it's just crappy. So, PHP has a function strpos() which will return the position of the first occurrence of a substring within a string. Quick! In what order do you put the variables? In this case, it's string to be searched, search string. What about preg_match()? Oh, there you put it in the reverse order! And really, when writing functions, there is no "proper" order, but if you're doing $string.preg_match('/^apple$/'), there's a clear order.

* Looking more at preg_match(). What does it return? It doesn't return a match, it returns a count of the matches it finds. If you want the matches, you need to pass in a variable that it will take a pointer to as an argument so that it can place the matches in there. Bleh! How would this be done in a nice OO-way? $var->preg_match('/^apple$/').count() would get you the count and otherwise you get the match returned. Easy in a way that requires less memorization of weirdness and doesn't feel so wrong. And crappy things like that are done throughout PHP where things are weird, but end up

* php.ini. Terrible idea. PHP allows you to change very important things install-wide, directory-wide, app-wide, ick-wide! It's not just magic quotes. It's more that you never quite know what you're deploying to in a bad way.

Finally, it's that PHP is an older-style language without the cool things that newer languages can do. PHP isn't bad per-se, but it isn't good either. The biggest thing it has going for it is that it's easy on shared hosting. With VPSs coming down in price to the point that they don't represent a huge premium over shared hosting, that's become less of an attraction. PHP is fine, but there's a decent amount to get annoyed with when creating a larger application.

Re: Ask HN: Why no love for PHP?

#35

Earlier quoted context omitted.

Except every year the 'cool' phones come and go, and PHP is still around, kick ass and taking names.

And my Nokia 5120 still boots up like it's first day when I pull it out of the discarded gadget drawer.

Do you mean because it's never been used?

Re: Ask HN: Why no love for PHP?

#36
PHP is not a language that was designed to be a language. It was originally a set of scripts that slowly morphed into a kind-of language. Because of that, PHP lacks a lot of the language features (threads, namespaces, proper OO design from the ground up) that "serious" languages all have. Ruby was buit to be the best language Matz could think of. Erlang was built to be a great language for programming telecoms. None of the "serious" languages morphed out of some CGI scripts.

As I already mentioned, PHP is not an OO language. It is a language that has OO as a feature, but the core API is not OO. This creates a very awkward mix of OO and procedural code.

One of the most embarrassing things about PHP comes from its complete lack of naming and ordering conventions. Look at the array functions. http://us.php.net/manual/en/ref.array.php 47 of these functions start with array_, 25 of them are a mismatch of whole words and partial words that happen to do array functions. The reason PHP documentation is so good is out of necessity. Without fantastic documentation, PHP would be completely unusable due to this staggering oversight.

Re: Ask HN: Why no love for PHP?

#37
I abandoned PHP about two years back. 8 months ago, after going to a conference and hearing the folks at Flickr talk, specifically Cal Henderson (http://www.krisjordan.com/2008/09/16/cal-henderson-scalable-...) I got re-energized to take another stab at making PHP pleasant to work with.

The results of my last push evolved into a PHP framework: Recess. (http://www.recessframework.org) It's got annotations for a declarative, meta-programming style. It's inherently RESTful (and more fine-grained content negotiation is coming soon). The Models/ORM are lazy so that you can chain together queries that evaluate at the last minute. Recess deploys just fine to commodity $5/mo servers and was designed to be lightweight and fast without giving up object-oriented design (a la Code Igniter).

What I feel gets lost in the "PHP is terrible" literature is a distinction between PHP as a programming language and PHP as a technology / platform. As a programming language, from an academic perspective, PHP is embarrassing. As a technology/platform it's incredibly well suited for web applications because that's exactly its intention. PHP's shared-nothing execution model, simple deployment, efficiency & performance make it a great technology for authoring web applications. Tooling has gotten much better too with Eclipse's PDT & XDebug.

If you're growing tired of PHP and looking for a platform/framework to develop on that is more productive and enjoyable try taking Recess for a spin. For me, at least, it's made PHP fun again: http://www.recessframework.org/

Re: Ask HN: Why no love for PHP?

#38

PHP has a few downsides, everything from poor naming conventions to security vulnerabilities. People around these parts are always looking for the cleanest solutions to their problems and the latest methods available. PHP's relative age and problems make it neither. That said, I coded my first startup in PHP. It's dead simple to make a dynamic web page with PHP, but it's also dead simple to create a huge mess. In tha…

Just like with C, there are definitely talented coders out there who can make PHP behave correctly. Sadly, they are a minority. Many of them move on to other languages and frameworks.

What does that mean? I'll take the compliment, but I'm not sure what the difficulty is in making PHP 'behave correctly.'

Re: Ask HN: Why no love for PHP?

#39
post #34

There are lots of reasons. * PHP attracts idiots. Partly that's because you don't need to know anything to make simple PHP. So, in the large pool of PHP programmers, there are a ton of idiots. And those idiots produce a lot of verbose code that gets used because it does something. Ruby, Python, Perl, etc. all put up a larger barrier because they don't just come with a session handler or whatnot built in. And that wee…

I think the first reason is probably the most significant. A lot of the other things are just warts and pet peeves, but what really got me down working with PHP professionally was the level of code I had to work with. Not only did I end up having to maintain flaming wreckages of code written by people who couldn't even properly be called amateurs, but after doing it for a couple years I found it very hard to improve my craft by seeking out good code to learn from.

I jumped headlong into Rails 4 years ago after having been enamored with Ruby over Perl for sysadmin type scripting and text-munging. Yeah Ruby has some bad warts too (the runtime!), but the quality of code in the community is an order of magnitude better.

Re: Ask HN: Why no love for PHP?

#40
I'm a big fan of PHP for myself. But I've seen enough of PHP script kiddies out there making nearly free (as in beer) websites/webapps. They become a mess in no time.

Mostly hacking phpnuke, joomla or some other messy portals. Hacked sites mostly never get any security updates or any kind. But employers having free work done are ok with this scheme so more and more script kiddies emerge.

Also there is not much thing going on PHP nowadays. Maybe PHP is at peek for it's purpose - doing web apps easy and quickly.

Post reply on HN