Why people hate PHP, a book from hell
blog.neattutorials.com
blog.neattutorials.com
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.
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
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.
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.
someArray.sort((a, b) => a - b);
var odd = (x) => x % 2 == 0;
highlightRows = rows.filter(odd);
function isLegalAdult(age, locality){
...
}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.
Heck, even the PHP manual tutorial is downright awful and desperately needs updating.
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.
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
<?php
return 42;
file b.php <?php
$a = include 'a.php';
var_dump($a); // (int) 42Of 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.
I've been told by numerous people that this is no longer the case, the value is cached.
Maybe they should just add to the file and compact it from time-to-time instead..
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.