Most of my hate is not directed at PHP but rather the code of the projects I run across written in PHP. It's not uncommon for there to be random whitespace and code thrown everywhere with no heed to a sensible MVC or other software architectural pattern.
I do occasionally run into well written and maintained software written in PHP and, while it's not my prefered language, it's quite readable and I can work with it.
PHP does have it's issues but they are exacerbated by the general community that uses it.
> Most of my hate is not directed at PHP but rather the code of the projects I run across written in PHP.
This is pure selection bias. There's great PHP code and there's horrible $YOUR_FAVOURITE_LANGUAGE code.
If you hate PHP because of this, you must also hate Java (since Android, at least, which at least halved the average competency of the community) Ruby (since Rails became too popular), JavaScript (see the jquery thread on the HN front page right now), Haskell (big ball of 2000 unorganized functions with two-letter argument names, anyone?), C# (This Is How Microsoft Does It So We Must Too) and Python (at least since Codecademy/Treehouse started unloading thousands of well-meaning but inexperienced Python programmers on the world). Don't even get me started about Perl and C++.
I'm not sure what's left. Clojure, Elixir, Turbo Pascal?
I said that there is great PHP code, I've run into many projects in PHP that are extremely well written. However, I run into more PHP projects that are not.
PHP is fantastically easy to get started using, it's probably the simplest way to start doing website development, and Wordpress runs many of the small websites we see today. I recommend it to anyone getting started in web development. But what this leads to in website development is me running into more code in PHP that is bad than good.
You are correct in saying that there's horrible $YOUR_FAVORITE_LANGUAGE code, I do run into it all the time, but I just tend to run into this problem more with PHP due to how amazingly low the barrier to entry is.
Since you brought up my favorite language, Python, I will go to say that at least Python forces people who write it to use sensible whitespace more or less. I can read most Python projects, even if they are really bad. In PHP I've seen whitespace and lines that stretch over 500 characters and combinations of tabs and spaces that make my brain hurt. This goes for any language that doesn't have strict whitespace rules but specifically PHP and even JavaScript, with their ability to inline code in HTML, have lead to some nightmare codebases that I've had to work on. That is not to say that Python doesn't have some silly long lines with people who try to get too creative with lambda functions but that's a rare occurrence. Also the fact that you cannot inline Python (without some silly libraries that do exist) you do get at least some separation of templates and model/views. This goes for Java and C# and whatever other web dev language you want to put in. PHP's ability to inline code is both incredible for new coders and a nightmare for readability if not done properly.
I think it's a bit silly that less-than-four-letter arguments/values/objects/functions are allowed in modern languages. I mean, what are the odds that the programmer is not writing horrible code in that scenario?
That's very subjective. Yes, one-letter variable names are usually a pain, but throwaway loop increments can be an exception. Three letter variable names are often perfectly acceptable, and optimal - what would you suggest I use instead of age, day, or max? Long variable names are often a massive pain, particularly those with multiple words separated by differing case or non-alpha characters.
Agreed. Every programming language/library/framework/etc will have ugly warts.
You shouldn't primarily evaluate a product based on the number/severity of ugly warts -- but rather on how much problems you will have from the warts, if you follow your coding standards and best practices.
(That said, I've never used PHP. E.g. the naming in the standard lib seems hard to not suffer from, but it ought not to be a major problem.)
I'd agree with this, but from an unusual perspective - I write some really, really bad PHP. So I thought I'd offer some perspective on where this actually comes from (from a sample set of 1).
PHP's documentation is almost too good. It's fantastic. My primary frustration dabbling with other languages is that no-one else has not only the language itself, but a huge subset of the core library documented to the standard that I've come to rely on from PHP.
But here also lays a huge problem. I'm not a programmer. I have next to no idea what MVC is, let alone what would qualify it as sensible. When it comes to architecture, I could give you a much more convincing description of flying buttresses than anything you'd hope to find in a codebase.
But what I can do, is break what I want to do down into small enough component tasks that I can find very workable examples within the PHP documentation, and then duct-tape these all together until I've accomplished my goal.
Now, the good news is that I know this is a terrible approach with terrible results, so I wouldn't dream of inflicting my results upon anyone else. But I thought I could offer a little insight onto how PHP enables such atrocities.
It's similar to the popular backlash against Bootstrap. Where Bootstrap enables me to kludge together a frontend with near no idea what I'm doing, PHP's documentation does the same for the backend. But I still find it difficult to blame the products themselves - I'm more than aware that this is my failing.
Is it really that much better? I've found e.g. the Python documentation for the core library is very good. It seems to me that it should be possible to slap together some Django approximately as easily as PHP, and you'd end up with something a little bit better.
Is it just that something like Django requires a bit of up-front install, whereas PHP you can write <?php in a file on your shared webhost and be rolling? Am I wrong about the documentation being up to the same standards? Or is there something else going on?
Laravel (or any other PHP framework) also requires an "up-front install", but you don't need a framework like Django to "slap" together a Python program for web purposes either. What you need is an understanding of what a CGI application does and how to deploy one with your favorite web server. Deploying a Python application with Apache/mod_wsgi (or nginx/uwsgi) is really no more difficult than deploying a PHP application with Apache/PHP-FPM or FastCGI.
I don't think you can apt-get install python and expect to be running a webserver. But I think we can all agree that running a python web app (properly) is 10 times easier than ruby.
True, but by doing apt-get install php you won't be up and running either. My point was really to clarify that you don't need a full blown framework to run basic Python scripts for web programming purposes and also to state that the barrier to entry for Python isn't really that much higher than PHP.
I think PHP has some of the best documentation I've ever come across. Particularly the comments section for every single command is incredibly helpful. I've learned tons and tons just from the comments. I think any programming language would be much improved if they copy PHP's documentation model.
(This is coming from a guy that does understand PHP very well, also MVC, objects, "patterns" even though I personally think that word is absurd :P)
As far as I can tell, these should be functionally similar, at least for my goal of returning an array as json.
The first thing to compare is the very first line - where the php docs tell me quite clearly what this function does. Compare to what I can only call waffle on the Python docs.
The php docs go on to tell me: what the arguments are, what types they are, and what options are acceptable. Followed by examples that start with the very basic, and go on to cover some more involved scenarios - but are all self-documenting and standalone.
The Python docs start off with some examples that frankly, aren't self-documenting. I'm still not sure what type is being passed, or returned, in the first example. The following examples appear to be trying to cover some edge cases, but don't say what, or why. This for me is the huge difference - the documentation is the last place I expect to be trying to guess what they mean.
We them get into the "basic usage" section where my eyes frankly glaze over.
It seems the Python docs to go into a lot more depth, so could be called better-documented from that point of view. But my original argument was that the PHP docs are incredibly accessible, and I stand by that.
PHP developers are much much more qualified than Python/Ruby/Java devs for the same price in my area. You can hire PHP dev who can TDD for $10/hour. Or you can have a Ruby junior who brags about Ruby and cannot ship things
Id say in the UK the contract rate is more like 60-70 Euros or £50 ph for an experienced developer maybe -20% for a very junior developer though most serious contract developers quote a day rate
> Including a function like count() or sizeof() within a loops execution condition is a bad idea. This expression will be executed with every iteration.
I've been told by numerous people that this is no longer the case, the value is cached.
I think PHPs big strength is the other point mentioned in the post: It enabled lots of people who are not really programmers to do some programming. Some of them developed into serious developers, some of them didn't. Being able to produce something slightly meaningful even without any skill is a big accomplishment, but it also means loads of erros, over estimated skill levels, security holes, unreadable code etc. The reason this doesn't happen to Haskel is that you become a computer scientist first and then learn that language. The reason is not a single bad book, where probably most programming languages have a few of.
There is tremendous depth to it which I am still exploring but to start and do the beginner kind of things I was wanting to do it is not hard.
Maybe not as easy as Python, but there is a huge gap between "not quite as easy as" and the "you need a CS degree and a Phd in Category Theory to even get started" rhetoric.
Here was about my first experience of Haskell. I don't mind admitting I bounced fairly hard at first. I've since done a bit more, but find it too limiting rather than freeing.
Prelude> foldr + [1,2,3]
<interactive>:14:9:
Couldn't match expected type ‘(a -> b -> b) -> b -> [a] -> b’
with actual type ‘[t0]’
Relevant bindings include
it :: (a -> b -> b) -> b -> [a] -> b (bound at <interactive>:14:1)
In the second argument of ‘(+)’, namely ‘[1, 2, 3]’
In the expression: foldr + [1, 2, 3]
In an equation for ‘it’: it = foldr + [1, 2, 3]
A lack of decent tutorials and resources to learn PHP is something the language really suffers from. Google "PHP tutorial" and almost everything you get is completely awful and uses 12-year-old (as in, from 12 years ago) programming practices.
Heck, even the PHP manual tutorial is downright awful and desperately needs updating.
It's always surprised me that Jeff has stuck with PHP. The guy is a very capable programmer who I thought would have moved on to bigger and better things.
I guess the market for tutorials and learning is larger for PHP than most other languages, except Javascript, possibly...
I've been programming since I was a kid, I'm 34 now, I've been selling code since I was 16 and I still use PHP for the web.
It has an intersection of features (speed of development, ease of deployment, availability of libraries, availability of programmers) that makes it a compelling choice for the web.
Everything else (except toy stuff) I do in Python.
TLDR; op blames awfull books that spread bad practices and then made PHP code ugly and insecure.
I personally don't care about PHP.
Now the PHP community is kinda funny.
Basically there are the people that use PHP as poor man's java, that feel the need to write 50 design patterns per file, who hates the other part of the community, the one that couldn't care less about "software engineering best practices".
So it's not much that people hate PHP, more like PHP developpers hate other PHP developers because they feel the need to be labelled as "good" PHP developpers, unlike the "bad" ones.
I'm now desperately trying to remember the PHP book I read in 2007. It was nowhere near as bad as the example here but I'm sure it used globals everywhere and had other bad examples.
It definitely reminds me of when I first tried learning javascript and every example I copied didn't work on my site. I distinctly remember Blizzard having some sort of moving graphic from diablo that I tried to just copy and paste into my site.
PHP is here to stay and will have better documentation over time. PHP programmers will start writing awesome, meaningful and standard code as more and more languages and tools make it possible to compile code in a specific language into a PHP code. One example is the Haxe Programming Language. I jumped onto other programming languages, such as Python and SPA with JS, some time ago; but I am now investing more of my time in Haxe.
All that being said, I am also wary of the all-in-one kit and its imminent trouble. I have been seeking comments on it from the public here - https://news.ycombinator.com/item?id=9111742
Why "will start writing [...] meaningful [...] code"? They already did, right? Just two examples are Wordpress and Facebook. There are many impacts made by PHP tools.
(Btw I'm one of the guys switching from PHP to Python, so this is not advertisment from a fan)
Thanks asmicom; I don't think I should be downvoted for expressing myself. That was my opinion. And I was also seeking comments from readers.
@erikb: There is a school of thought those apps - FB, wordpress,etc - don't contain lines of code with best practices. I am however glad they are released on non-restrictive licenses and the general public are contributing to the various projects.
All I can say is that PHP is here to stay. I have not written a whole app/project in PHP5 before but with PHP4. I however think kits/tools like Haxe AND apps like FB & WP will keep PHP in the market for a very long time.
PHP is awesome. It's so easy, i never had to read a book about it. Powers the web, and is ubiquitous. Sweet deal, instead of learning 10 different trendy languages every year, i stuck to it for more than 13 years now, and learned other much more important stuff. Wanna do something too complex? You wouldn't use a scripting language for that anyway. There's a tool for everything in PHP and it's fast. PHP made me money, i havent found something that's better overall.
One of the major reasons I dislike PHP is because of the include mechanism. When you include a file, you literally include the code of that file on that spot. You can't assign it to a variable to namespace it or something. Also the file that get's included can use the variables of the file it gets included into. This allows for some crazy behavior that can be very hard to analyze.
So to keep an overview of what you're including or what actually gets included, you'll have to make rules like "the filename should be the classname lowercased" or "all views for this module are in this specific file" and "included files may never use variables of files they are included into".
A lot of PHP frameworks have these kind of conventions. That's good, people are less prone to create unclear program behavior, but, it's still possible if they want. And anyway, it's sad that you need these conventions to help you use the language in a sensible way.
That's my biggest annoyance of PHP anyway. Don't know how much people feel the same way?
The autoloading basically fixes this, at least insomuch as you use the namespace that you want rather than require a file.
Of course, you need an autoloader, and writing one is complicated enough that you'll want to use a pre-existing one, which means sticking to whatever conventions it uses for storing modules in the filesystem (probably a PSR), but realistically you're going to want to do this anyway.
So yeah, it's more complicated than it needs to be but on the upside it's a lot more flexible too; you can pretty much define whatever naming convention you can think of.
62 comments
[ 3.7 ms ] story [ 124 ms ] threadI do occasionally run into well written and maintained software written in PHP and, while it's not my prefered language, it's quite readable and I can work with it.
PHP does have it's issues but they are exacerbated by the general community that uses it.
This is pure selection bias. There's great PHP code and there's horrible $YOUR_FAVOURITE_LANGUAGE code.
If you hate PHP because of this, you must also hate Java (since Android, at least, which at least halved the average competency of the community) Ruby (since Rails became too popular), JavaScript (see the jquery thread on the HN front page right now), Haskell (big ball of 2000 unorganized functions with two-letter argument names, anyone?), C# (This Is How Microsoft Does It So We Must Too) and Python (at least since Codecademy/Treehouse started unloading thousands of well-meaning but inexperienced Python programmers on the world). Don't even get me started about Perl and C++.
I'm not sure what's left. Clojure, Elixir, Turbo Pascal?
PHP is fantastically easy to get started using, it's probably the simplest way to start doing website development, and Wordpress runs many of the small websites we see today. I recommend it to anyone getting started in web development. But what this leads to in website development is me running into more code in PHP that is bad than good.
You are correct in saying that there's horrible $YOUR_FAVORITE_LANGUAGE code, I do run into it all the time, but I just tend to run into this problem more with PHP due to how amazingly low the barrier to entry is.
Since you brought up my favorite language, Python, I will go to say that at least Python forces people who write it to use sensible whitespace more or less. I can read most Python projects, even if they are really bad. In PHP I've seen whitespace and lines that stretch over 500 characters and combinations of tabs and spaces that make my brain hurt. This goes for any language that doesn't have strict whitespace rules but specifically PHP and even JavaScript, with their ability to inline code in HTML, have lead to some nightmare codebases that I've had to work on. That is not to say that Python doesn't have some silly long lines with people who try to get too creative with lambda functions but that's a rare occurrence. Also the fact that you cannot inline Python (without some silly libraries that do exist) you do get at least some separation of templates and model/views. This goes for Java and C# and whatever other web dev language you want to put in. PHP's ability to inline code is both incredible for new coders and a nightmare for readability if not done properly.
You shouldn't primarily evaluate a product based on the number/severity of ugly warts -- but rather on how much problems you will have from the warts, if you follow your coding standards and best practices.
(That said, I've never used PHP. E.g. the naming in the standard lib seems hard to not suffer from, but it ought not to be a major problem.)
PHP's documentation is almost too good. It's fantastic. My primary frustration dabbling with other languages is that no-one else has not only the language itself, but a huge subset of the core library documented to the standard that I've come to rely on from PHP.
But here also lays a huge problem. I'm not a programmer. I have next to no idea what MVC is, let alone what would qualify it as sensible. When it comes to architecture, I could give you a much more convincing description of flying buttresses than anything you'd hope to find in a codebase.
But what I can do, is break what I want to do down into small enough component tasks that I can find very workable examples within the PHP documentation, and then duct-tape these all together until I've accomplished my goal.
Now, the good news is that I know this is a terrible approach with terrible results, so I wouldn't dream of inflicting my results upon anyone else. But I thought I could offer a little insight onto how PHP enables such atrocities.
It's similar to the popular backlash against Bootstrap. Where Bootstrap enables me to kludge together a frontend with near no idea what I'm doing, PHP's documentation does the same for the backend. But I still find it difficult to blame the products themselves - I'm more than aware that this is my failing.
Is it just that something like Django requires a bit of up-front install, whereas PHP you can write <?php in a file on your shared webhost and be rolling? Am I wrong about the documentation being up to the same standards? Or is there something else going on?
(This is coming from a guy that does understand PHP very well, also MVC, objects, "patterns" even though I personally think that word is absurd :P)
Here's an example I ran into recently, taking my first babysteps into Python: https://docs.python.org/2/library/json.html vs http://php.net/manual/en/function.json-encode.php
As far as I can tell, these should be functionally similar, at least for my goal of returning an array as json.
The first thing to compare is the very first line - where the php docs tell me quite clearly what this function does. Compare to what I can only call waffle on the Python docs.
The php docs go on to tell me: what the arguments are, what types they are, and what options are acceptable. Followed by examples that start with the very basic, and go on to cover some more involved scenarios - but are all self-documenting and standalone.
The Python docs start off with some examples that frankly, aren't self-documenting. I'm still not sure what type is being passed, or returned, in the first example. The following examples appear to be trying to cover some edge cases, but don't say what, or why. This for me is the huge difference - the documentation is the last place I expect to be trying to guess what they mean.
We them get into the "basic usage" section where my eyes frankly glaze over.
It seems the Python docs to go into a lot more depth, so could be called better-documented from that point of view. But my original argument was that the PHP docs are incredibly accessible, and I stand by that.
I've been told by numerous people that this is no longer the case, the value is cached.
There is tremendous depth to it which I am still exploring but to start and do the beginner kind of things I was wanting to do it is not hard.
Maybe not as easy as Python, but there is a huge gap between "not quite as easy as" and the "you need a CS degree and a Phd in Category Theory to even get started" rhetoric.
Prelude> foldr + [1,2,3]
<interactive>:14:9: Couldn't match expected type ‘(a -> b -> b) -> b -> [a] -> b’ with actual type ‘[t0]’ Relevant bindings include it :: (a -> b -> b) -> b -> [a] -> b (bound at <interactive>:14:1) In the second argument of ‘(+)’, namely ‘[1, 2, 3]’ In the expression: foldr + [1, 2, 3] In an equation for ‘it’: it = foldr + [1, 2, 3]
1. + contains only special characters and must be used either as infix function (1 + 2) or be enclosed in brackets
2. You need an initial value for the accumulator. You are reducing a list to a single value, you need to start somewhere
Please, gurus of Haskell, correct me if I'm wrong, I've just recently started to learn the language
Heck, even the PHP manual tutorial is downright awful and desperately needs updating.
[1] https://laracasts.com/
I guess the market for tutorials and learning is larger for PHP than most other languages, except Javascript, possibly...
It has an intersection of features (speed of development, ease of deployment, availability of libraries, availability of programmers) that makes it a compelling choice for the web.
Everything else (except toy stuff) I do in Python.
I personally don't care about PHP.
Now the PHP community is kinda funny. Basically there are the people that use PHP as poor man's java, that feel the need to write 50 design patterns per file, who hates the other part of the community, the one that couldn't care less about "software engineering best practices".
So it's not much that people hate PHP, more like PHP developpers hate other PHP developers because they feel the need to be labelled as "good" PHP developpers, unlike the "bad" ones.
The ignores the "design pattern madness" and the "beginners" and just uses PHP as a programming language to do software development in.
It's just another language to me and I treat it as such.
All that being said, I am also wary of the all-in-one kit and its imminent trouble. I have been seeking comments on it from the public here - https://news.ycombinator.com/item?id=9111742
(Btw I'm one of the guys switching from PHP to Python, so this is not advertisment from a fan)
All I can say is that PHP is here to stay. I have not written a whole app/project in PHP5 before but with PHP4. I however think kits/tools like Haxe AND apps like FB & WP will keep PHP in the market for a very long time.
So to keep an overview of what you're including or what actually gets included, you'll have to make rules like "the filename should be the classname lowercased" or "all views for this module are in this specific file" and "included files may never use variables of files they are included into".
A lot of PHP frameworks have these kind of conventions. That's good, people are less prone to create unclear program behavior, but, it's still possible if they want. And anyway, it's sad that you need these conventions to help you use the language in a sensible way.
That's my biggest annoyance of PHP anyway. Don't know how much people feel the same way?
file a.php
file b.phpOf course, you need an autoloader, and writing one is complicated enough that you'll want to use a pre-existing one, which means sticking to whatever conventions it uses for storing modules in the filesystem (probably a PSR), but realistically you're going to want to do this anyway.
So yeah, it's more complicated than it needs to be but on the upside it's a lot more flexible too; you can pretty much define whatever naming convention you can think of.
Maybe they should just add to the file and compact it from time-to-time instead..