Live data from Hacker News

Stack Overflow: Defend PHP - convince me it isn't horrible

stackoverflow.com

11–20 of 74 posts

Re: Stack Overflow: Defend PHP - convince me it isn't horrible

#11
post #4

PHP is great if you need to get some small thing up and running yesterday. PHP is also great if an out of the box solution will almost fit the bill due to the fact that there are so many. Just take a box and do some small modifications, voila, done!

Like someone else already said, "small thing"... like Facebook? Like Flickr? Like Wikipedia? Like Digg? :)

Re: Stack Overflow: Defend PHP - convince me it isn't horrible

#13
I'm spending most of my time maintaining a web application consisting of around 150k lines of PHP code. We (well - initially, it was just me) began development back in 2004 but since then the application has grown constantly.

Back in 04, I already felt some reservations against PHP, but that's what I knew best and that's what was most used for the web (Rails might have been around, but not really known - other ruby options were not quite there yet. Python I disliked and Java I. don't. touch.).

The application was written in PHP5, initially developed on some RC of 5.0.0 and I was careful to keep a clean style and not using deprecated code.

This lead to a quite clean application that I could really be proud of. And still: While it has suffered from sometimes not quite reasonable customer demands, it's still very good at what it's doing and while there might be some dead bodies rotting in the code, it's nowhere near daily WTF material (aside of some bugs we have a good laugh at and fix shamefully).

Still. I have some bad gripes with PHP that made me stop doing anything new in that language.

I can easily live with the usually quoted problems though:

- parameter order in library function? I don't care - my IDE lists them.

- Huge base library? I don't care as the stuff I don't need doesn't cost me anything but disk space and the stuff I do need, I'm glad is there.

- No namespaces? Yeah. Bit me a couple of times, but I can work around that - besides, with 5.3 we got namespaces, so this doesn't count any more

- Performance issues? It's fast enough for said application.

- Security? It's just as secure as any other language you can write insecure code in (i.e. all of them).

- Allows intermixing of layout and code? Sure, but you don't have to. If you have any sense what so ever, all requests go through a central /index.php and all other code is in some not-publicly accessible location and emits no html what so ever. All output is generated using any of the thousands of templating libraries.

What really disturbs me about PHP is its type conversion rules. 1 == '1' or even worse 'foobar' == 0, or '123n' == 123. This is cause for so many subtle bugs.

Just use === you tell me? Sure, but then you clutter your code with an insane amount of isset()'s and isint()'s and whatnot - the fact that the database library I'm using (pgsql) returns everything as strings doesn't help that cause either.

The other thing is the really clumsy syntax. Array literals, anonymous functions, closures (with explicit declaration of all variables of the outer scope you want access to), operators, even just the lack of named function parameters. The syntax is clumsy and all the elegant code you see even from JavaScript just gets bloated and unreadable once you port it to PHP.

These two issues made me do stuff in Ruby, Python(3) and lately a lot of Node.js, but the maintenance of that huge application remains to be the main part of my day-job and even though the two issues really bug me, it's still not painful enough to really be complaining (or, heaven forbid, port the thing to whatever-other-language-thats-currently-hip).

So in retrospect, while I'm as die-hard a PHP user as you can get with many, many lines of PHP under my belt and while I do find some of the stuff highly enjoyable (php's arrays that are also ordered hashes for example. Or the really easy and accessible web-server/HTTP integration), I also dislike it quite a bit to the point of being unwilling to start something new in PHP.

Re: Stack Overflow: Defend PHP - convince me it isn't horrible

#14
post #8
post #4

PHP is great if you need to get some small thing up and running yesterday. PHP is also great if an out of the box solution will almost fit the bill due to the fact that there are so many. Just take a box and do some small modifications, voila, done!

...or big thing running yesterday, right? Take Facebook for an example. To me, Facebook seems like a pretty complicated piece of software. The concept isn't very complicated but there are so many features all over the place.

He didn't say you _can't_ use PHP for such things, he said PHP is "great" for getting smaller sites built quickly. It's possible to build very large apps with PHP alone, if you like, but there are other solutions I think are preferable. Most of them weren't even available when Facebook was born.

For example, I would rather build a Facebook-sized app in Rails than a PHP framework, especially with Rails 3's new features. There are some very capable PHP frameworks out there, but you'll still end up writing much larger models and a lot more code than if you were using Rails.

Re: Stack Overflow: Defend PHP - convince me it isn't horrible

#15
These topics always just smell of "Now I'm a grown up programmer I'm going to tell the world how much I understand by slamming an easy target language".

I love PHP and have used it for years since moving away from asp.net and agree with some of the posters arguments as a theoretical principle, but as day-to-day PHP developer I also say so what. Naming and parameter inconsistencies? Yes, my libraries have that too and I can at least learn the PHP ones with some experiernce. I don't know any asp.net developer that doesn't have to use some kind of tool to help them find where System.Obscure.FoundItOnline.Function exists in the monster .net namespace system. It allows me to be productive and allows me to be the gatekeeper of how well or poorly I implement things. This is a crucial point of the constant argument about poor PHP logic/presentation support for me, I can happily write mixed and messy code for a £500 job or I can write some clever system that implements caching and output buffer manipulation and have a great template system.

There are far too many people spending far too much time thinking that academic level programming considerations are applicable in every detail to every day programming practices of web developers.

Re: Stack Overflow: Defend PHP - convince me it isn't horrible

#16
post #9

To be honest I don't think case insensitivity is really that much of an issue. Common Lisp is case insensitive as well and I have never had any problems with that.

They could have made it fully case sensitive, or fully case insensitive... but they went for the confusing middle point:

  foobar() == FOOBAR()
but

  $foobar != $fooBar
And then there was that fun issue with the Turkish locale and function names...

Re: Stack Overflow: Defend PHP - convince me it isn't horrible

#17
I think this is the wrong approach. The guy should try to convince me that PHP is bad. That PHP has never not did what I wanted it to do. That I need to invest time and switch to some other language because it's better for my needs and purposes, and the switch will quickly get me to a level of expertise that I have with PHP now.

The fact of the matter is PHP is ugly and that's really it. I can live with ugly because I know it and it does everything I've ever asked it to.

Frankly, it's no different than me switching from English because it has quirks.

Re: Stack Overflow: Defend PHP - convince me it isn't horrible

#18
I wish I could ignore PHP, but it's just so darn ubiquitous. Most webhosts priced within the means of "normal" people have PHP, while far superior (IMO) platforms like ASP.NET are the exception. Until webhosts can be convinced to support a wider range of platforms, I fear humanity will never be freed of the bonds of PHP.

Bill, hates PHP with the heat of a thousand suns.

Re: Stack Overflow: Defend PHP - convince me it isn't horrible

#19
From a programming language perspective, PHP is somewhat horrible (PHP 5.3 less so, but still). I guess nobody will deny that. But from practical perspective, PHP is very suitable tool for many tasks and has huge ecosystem behind it. Complex real-world websites and applications have been successfully built with PHP. Isn't that proof enough?

Do you consider yourself a purist or pragmatic? In the latter case, PHP may be worth dating for a while.

Re: Stack Overflow: Defend PHP - convince me it isn't horrible

#20
post #19

From a programming language perspective, PHP is somewhat horrible (PHP 5.3 less so, but still). I guess nobody will deny that. But from practical perspective, PHP is very suitable tool for many tasks and has huge ecosystem behind it. Complex real-world websites and applications have been successfully built with PHP. Isn't that proof enough? Do you consider yourself a purist or pragmatic? In the latter case, PHP may b…

"Complex real-world websites and applications have been successfully built with PHP."

Thanks to PHP or in spite of PHP?

Post reply on HN