PHP has a lot of functions that actually take away lots of pain, but you have to know they're there. If only this fellow had found implode(), he wouldn't have needed to write enumerate().
I was a PHP hater for years, but I find that for certain types of problems, it really is the right solution.
[Edit, later: and you can (and should) paper over some of his other complaints. PHP isn't a great language qua language, but it has such great penetration that it almost doesn't matter.]
Sure. Social networking sites like the one in my user profile. Pretty much any site where the building of the site would be fairly trivial in any language, and scaling is the problem: with PHP, you can start it on any cheap host and port it in minutes to better servers, because you don't have to worry so much about setup. If the idea itself is innovative, but there's nothing interesting about the code that the site runs on, PHP is an excellent candidate.
I've built sites (some for clients, some of my own) in a bunch of languages, and there's a certain amount of tradeoff between setup/installation and actual coding. For whatever reason, languages which are more fun or more productive to code in require more setup time, and are likely to be already installed on a random new server almost exactly in reverse proportion with how fun/productive they are. It's eerie.
Pretty much any site where the building of the site would be fairly trivial in any language, and scaling is the problem: with PHP, you can start it on any cheap host and port it in minutes to better servers, because you don't have to worry so much about setup.
Aren't most PHP apps dependent on weird php.ini settings?
And anyway, the "real" langauges are equally easy to deploy. Get yourself a $20 slicehost account (to start with), add two lines to apache's config to enable FastCGI, then just copy your app up to that server. That's all there is to deploying Perl, Ruby, and Python these days.
With Perl and Catalyst, I can "make catalyst_par" and get a file that contains the entire application; including the version of Perl I am developing with. That way I know for sure it will work when I copy it to production. (Yes, this means I have to use the same architecture for both development and deployment. I do.)
Weird php.ini settings can almost always still go in the directory with the php files, so just copying the directory automagically makes everything work right. Some settings don't work this way, of course, but I'm not sure which those would be, offhand.
If you're using Python, for example, you're probably also using some framework... for years I used Webware for Python, and more recently web.py. Both require careful attention to get working in a convenient fashion, in my opinion.
>Can you give some examples of those certain types of problems?
Wikipedia, Flickr, Facebook, Wordpress... ;)
Seriously though - in the real world, language strengths and weaknesses are very different from CS theory or discussion such as this one.
PHP's popularity in itself has serious benefits:
- You can pretty much install PHP anywhere because no host can afford not to support it well.
- It will usually scale pretty decently and work reasonably well with your DB, OS and web server out of the box, because it has enough users that it got tested in many edge case installations.
- Finding code is easy, and usually a new API provider will have a PHP library soon enough, if they want to get their API widely used.
- Last but certainly not least - it's easier to find competent PHP coders than almost any language. There are a lot of incompetent ones and, as in any language, few excellent ones, but there's a larger base of competent-enough coders than Python or Ruby (or Lisp ;))
In my opinion most criticism of PHP misses the point. No question PHP is not an elegant language. By the same token, you could say Esperanto is far more clean than English, French more elegant and Italian more beautiful. But in the end, English is the one that's used.
I've found that my limited PHP knowledge has been great for little tiny projects.
For example, something like http://soindie.com (which isn't mine) would be a huge pain to set up with some enormous framework. But with a few lines of PHP, a mysql database, and you're done.
"would be a huge pain to set up with some enormous framework."
It is possible to write Web apps in Ruby, Python, et al without some enormous framework. They all have basic DB wrapper libs and straightforward templating tools.
There are a variety of patches available that give you anonymous functions, as well as closures. You need to seek it out and compile. But, I guess from your laughter, that shouldn't be an issue for you since you've got the CS thing down.
I'd love to see that patch merged into PHP, but even then, it will take some time to change the habits of people using this in libraries, frameworks, etc.
Seems like blog spam, but this post has said nothing new from all of the other 'PHP sucks' posts, so I have no idea why you decided to make yet another one.
I like PHP since it is so easy to deploy and it can be used for anything from a simple two page website to a full-blown web application. Being written in PHP also means that you are not limited in hosting.
If you're a startup creating a single web app, then fine, use Python with mod_wsgi or Rails and five mongrel servers. But if you're creating basic CRUD websites, especially more than one, then there is nothing wrong with PHP. I can fit dozens of low-traffic websites on a $20/mo 256MB RAM server using Apache and mod_php; try doing that with Rails.
As I said, if I was going to focus on a single web app with its own dedicated server, then I would definitely look at Python and mod_wsgi, but since I create a lot of 'smaller' websites (nothing too complex), it is much less of a hassle using PHP since I can fit all of them nicely on a single, cheap server.
I think it means a blog post which kind of reads like it was written by a person, but is really a mushing together of paragraphs and sentences from other posts in order to get some traffic and serve ads.
It is not at all obvious that {...} is better than, say, array(...) for a language that has operator braces {}. PHP's array constructs are a little verbose, but they are visually distinguishable and thus are not that bad at all.
{...} as an array/dictionary literal makes more sense in a language like Python, where braces are not used otherwise.
If creating a new language that looked like PHP/C/Java/etc, you could use {} for both blocks and arrays (and assoc arrays, like PHP) by making blocks a special case of arrays, conceptually. Then {0; 1; 2; 3;} would be an array of four elements, and as a bonus it would free up [] for something else. :)
Like in C or Perl, OK, but that makes both unreadable for humans rather than for compilers, that's what I'm saying. So the reasons behind PHP's array() construct are not trivial.
The day I settled on PHP was the day I was finally able to focus on the guts on my project, not on the infostructure. Let me explain...
I used to use what I thought was the "best tool for the job". Javascript/HTML/CSS for the client, another language for the server, another DBMS, and a separate server. And I spent half of my time trying to figure out why one thing didn't work with another. It was never anything big, but just bad enough to slow me down (performance, scaling, security).
Then a friend asked why I was messing with all that. He said to just download an Apache/PHP/MySql stack, install it, and forget about it. So I did.
Sure I hate the syntax, especially the dollar signs starting variable names, but I have never had a problem getting it to do exactly what I wanted. If I ever had a question, there were a hundred places to turn for help. And I never had to worry about one technology working with another.
I've always been a non-conformist when it came to tech, probably to get an edge on everyone else. But I learned the hard way, there's a time to conform and a time to be a maverick. I'd rather conform with a standard platform and "do my own thing" with my apps.
I wrote my first startup in PHP - No Smarty, no Cake, no Pear, just PHP. And it worked!
PHP leads the developer down the easy path then locks them into a big codebase. Yes, it has it's problems, but in the end it works or can be trained to work.
That said, I'm seriously thinking of Python/Django or Rails for my next project.
If you say php sucks, then go get some sleep and think again.
Thats the easiest language any noob can start web development with. Lots of libraries and resources. Just do a search for 'web development tutorial' and you'll find that every 10th good tutorial will be about php. Python is easier than php, but every cheap host supports php.
And another fact: you can even create desktop apps with php. There a GTK extension to php. Google PHP-GTK for more.
PHP has many good lightweight frameworks that put the fun back into building web apps. CodeIgniter and KohanaPHP are especially lightweight. It isn't much fun coding web apps in raw Ruby, Python or any language.
27 comments
[ 0.73 ms ] story [ 73.0 ms ] threadI was a PHP hater for years, but I find that for certain types of problems, it really is the right solution.
[Edit, later: and you can (and should) paper over some of his other complaints. PHP isn't a great language qua language, but it has such great penetration that it almost doesn't matter.]
Can you give some examples of those certain types of problems?
I've built sites (some for clients, some of my own) in a bunch of languages, and there's a certain amount of tradeoff between setup/installation and actual coding. For whatever reason, languages which are more fun or more productive to code in require more setup time, and are likely to be already installed on a random new server almost exactly in reverse proportion with how fun/productive they are. It's eerie.
Aren't most PHP apps dependent on weird php.ini settings?
And anyway, the "real" langauges are equally easy to deploy. Get yourself a $20 slicehost account (to start with), add two lines to apache's config to enable FastCGI, then just copy your app up to that server. That's all there is to deploying Perl, Ruby, and Python these days.
With Perl and Catalyst, I can "make catalyst_par" and get a file that contains the entire application; including the version of Perl I am developing with. That way I know for sure it will work when I copy it to production. (Yes, this means I have to use the same architecture for both development and deployment. I do.)
If you're using Python, for example, you're probably also using some framework... for years I used Webware for Python, and more recently web.py. Both require careful attention to get working in a convenient fashion, in my opinion.
And scaling with those languages is a solved problem.
Wikipedia, Flickr, Facebook, Wordpress... ;)
Seriously though - in the real world, language strengths and weaknesses are very different from CS theory or discussion such as this one.
PHP's popularity in itself has serious benefits:
- You can pretty much install PHP anywhere because no host can afford not to support it well.
- It will usually scale pretty decently and work reasonably well with your DB, OS and web server out of the box, because it has enough users that it got tested in many edge case installations.
- Finding code is easy, and usually a new API provider will have a PHP library soon enough, if they want to get their API widely used.
- Last but certainly not least - it's easier to find competent PHP coders than almost any language. There are a lot of incompetent ones and, as in any language, few excellent ones, but there's a larger base of competent-enough coders than Python or Ruby (or Lisp ;))
In my opinion most criticism of PHP misses the point. No question PHP is not an elegant language. By the same token, you could say Esperanto is far more clean than English, French more elegant and Italian more beautiful. But in the end, English is the one that's used.
For example, something like http://soindie.com (which isn't mine) would be a huge pain to set up with some enormous framework. But with a few lines of PHP, a mysql database, and you're done.
It is possible to write Web apps in Ruby, Python, et al without some enormous framework. They all have basic DB wrapper libs and straightforward templating tools.
http://us2.php.net/create_function
http://www.opendogs.org/pub/php-5.3dev-071228a.patch
You'll have to backpatch it for 5.2.6 but it took all of an afternoon for us to do.
At massify, we run a patched version of PHP that provides all of the above.
I like PHP since it is so easy to deploy and it can be used for anything from a simple two page website to a full-blown web application. Being written in PHP also means that you are not limited in hosting.
If you're a startup creating a single web app, then fine, use Python with mod_wsgi or Rails and five mongrel servers. But if you're creating basic CRUD websites, especially more than one, then there is nothing wrong with PHP. I can fit dozens of low-traffic websites on a $20/mo 256MB RAM server using Apache and mod_php; try doing that with Rails.
As I said, if I was going to focus on a single web app with its own dedicated server, then I would definitely look at Python and mod_wsgi, but since I create a lot of 'smaller' websites (nothing too complex), it is much less of a hassle using PHP since I can fit all of them nicely on a single, cheap server.
Best advice i got.
{...} as an array/dictionary literal makes more sense in a language like Python, where braces are not used otherwise.
I used to use what I thought was the "best tool for the job". Javascript/HTML/CSS for the client, another language for the server, another DBMS, and a separate server. And I spent half of my time trying to figure out why one thing didn't work with another. It was never anything big, but just bad enough to slow me down (performance, scaling, security).
Then a friend asked why I was messing with all that. He said to just download an Apache/PHP/MySql stack, install it, and forget about it. So I did.
Sure I hate the syntax, especially the dollar signs starting variable names, but I have never had a problem getting it to do exactly what I wanted. If I ever had a question, there were a hundred places to turn for help. And I never had to worry about one technology working with another.
I've always been a non-conformist when it came to tech, probably to get an edge on everyone else. But I learned the hard way, there's a time to conform and a time to be a maverick. I'd rather conform with a standard platform and "do my own thing" with my apps.
I wrote my first startup in PHP - No Smarty, no Cake, no Pear, just PHP. And it worked!
PHP leads the developer down the easy path then locks them into a big codebase. Yes, it has it's problems, but in the end it works or can be trained to work.
That said, I'm seriously thinking of Python/Django or Rails for my next project.
Hey go get sexy and python yourself.
If you say php sucks, then go get some sleep and think again.
Thats the easiest language any noob can start web development with. Lots of libraries and resources. Just do a search for 'web development tutorial' and you'll find that every 10th good tutorial will be about php. Python is easier than php, but every cheap host supports php.
And another fact: you can even create desktop apps with php. There a GTK extension to php. Google PHP-GTK for more.