I think PHP is disproportionately targeted for rants; it’s the language everyone loves to hate. Despite the proliferation of posts that list the 1 trillion things PHP does wrongly, more than 70% of all websites run PHP on their servers. Even more interestingly, ‘better’ languages like Ruby are below PHP in the TIOBE index ( a language ranking metric). Definitely, PHP must be doing something right, no?
Personally, I am pretty much indifferent to the language (or any other language for the matter); it does what it needs to do. Now, don’t start another debate around this post.
How I came to learn PHP
I had to learn PHP during my 6-month undergrad internship; I would have preferred a Java-related job however, after 6 weeks of extremely difficult job-hunting, I was ready to take up anything. I wrote lots of PHP code, lots of baaaaaad code – the type that makes you cringe, rant about PHP and scream at the developer. The only rule I didn’t break was using proper variable names; all other rules ( DRY, YAGNI, OOP concepts) were routinely chucked out of the window.
It wasn’t PHP that made me write bad code, it was rather due to my amateur software development skills – that was my first real-life software development experience. However, I got to write some fun code too Alhamdulilah; a cool timetable generating algorithm, do some Linux and toyed around with networking ( I dropped that afterwards).
The Bad Parts of PHP
All languages have flaws and PHP is no exception; here are some of the reasons why people say PHP is baaaad for your programming health :D:
- The language wasn’t really designed but grew by accreting features. So it feels kind of clunky…
- Built-in libraries and functions are inconsistent.
- The naming convention is a mix of different naming styles
- camelCase: getName()
- under_score e.g. array_combine()
- joinedwords e.g. localtime()
- modulename_function: libxml_clear_errors()
- No Unicode support.
- Slow; of course, what do you expect?
- Huge libraries; PHP has functions for nearly everything you’ll ever need: regular expressions, URL parsing etc.
- Awesome database support.
- Familiar syntax; similar to the C/Java family.
- Great community – the PHP community is sooooooo active.
- Widely supported by hosting companies and is extremely widespread.
- Easy to use:
- Install WAMP/LAMP/XAMPP and get coding.
- Low deployment and maintenance demands – you don’t need 6 months to launch :)
- Easily integrated with most applications and frameworks.
- Extensible platforms exist e.g. wordpress, Joomla, Drupal.
Developing in PHP
Most developers start out with Macromedia Dreamweaver and they write extremely long monolithic files that are poorly structured and organized – ugly spaghetti code. Amateur developers don’t care for two reasons: little development experience and they get to build stuff. Ultimately, without improvement, these developers are responsible for the bulk of awful PHP code existing out there. There is little that can be done about this; however, if you have bad PHP code, please hide it until it’s improved. There are already enough rants on the internet…
Hopefully, you’ll realize the flaws in your development skills and leave Dreamweaver for an IDE (I personally think Netbeans is awesome). You’ll might go ahead to learn about, NoSQL DBs, ORMs and a couple of other good things.
Finally, maybe you’ll move on to other languages and come to see your old PHP code as ugly. If this happens, just don’t forget that you’ve probably improved your programming skills by learning a new language so don’t blame PHP totally – you were a worse programmer before. Remember this before you start ranting.
Bjarne Stroustrup said: “There are only two kinds of languages: the ones people complain about and the ones nobody uses”.
Agreed that it’s not be the best language but come on, it gets things done. The language is way too popular today, has excellent support and helps you to get things done easily.
22 thoughts on “The language series: PHP”
From my perspective, there are a few other problems in PHP that deserve to be critiqued:
1) Dependency management is awful. (Nonexistent, actually – there are entire applications built to assist with that, but they are all messy, IMO)
PHP didn’t really have libraries in mind when it was first designed. Consequently, what inter-module dependency management there is appears to be a hack in the worst possible way. As a software developer and a computer scientist I find this to be a particularly offensive aspect of PHP.
2) Debugging sucks. Frankly, debugging anything that is going to be processed within an HTTP server environment is awful in my experience, and interpreted languages like PHP and Perl are simply ugly to debug as well. This is an area where the supporting tools are years behind the language itself.
3) Weakly Typed language. PHP is not strongly typed at all. This is seen as a “benefit” by many whose programming lives are spent in scripting languages. I am less convinced of the “benefit” here, especially from a perspective of long term maintainability of code written in PHP. Large, complex libraries such as Zend Framework run the risk of becoming unusable or worse, dangerous to use, if you start tossing incorrect data types at them – and it is impractical for most developers to go in and reverse engineer the framework’s code in order to be able to develop in it. Going back to code that is old becomes an exercise in sidestepping fragile constructs.
(Bear in mind that my background includes the other end of the spectrum – extremely strongly typed language environments such as Ada, Pascal and Oberon as well as the more flexible environments like C and C++ – so I’m looking at this through the lens of many years with a lot of different languages)
4) ‘Swiss Army Knife’ Mentality
This is more of a concern I have with any language. Each language has its sweet spot that it fits into. Unfortunately, there always seem to be developers who are willing to try and shoehorn their favourite language into places it really doesn’t bring strength.
Some of the libraries I’ve seen for PHP give me the same impression of forcing the language into domains where it doesn’t really work well. (I remember someone trying to use a BASIC language interpreter to do fluid dynamics calculations a number of years ago – that didn’t go well either) Believe it or not, there are still places where the best language for the job is Fortran. (and I would never use Fortran for driving a website!)
Scripting languages seem to be particularly prone to people trying to use them in ways that they really aren’t that good at.
Definitely, different languages have their strengths.
Thanks a lot for the deep explanation.
I agreed with your opinion.
Good dynamic language though scalability could be frustrating with it. Facebook eventually went for hiphop. Could be used just like ruby when you are beginning a new startup.
You have a point: PHP works and it’s easy to deploy :)
If you ever setup it and did for other language you can realize which php is hardest for deploy.
Well, it is relatively easy to setup if you are satisfied with a generic setup and don’t really need a custom dev environment.
Interesting article. While I started playing with programming in vb6 , I would consider php my first major language. I know one of the really terrible stuff with php is that it allows you get away with a lot of non standard and really dangerous stuff(I cringe at some codes I see today and some I wrote a few yesrs back). But I think this has something to do with the character of the developer. Because php has got a lot of standard ways of dealing with programming problems the choice is the developers. In my case for example I have moved from hacking with php to proper software development with php. Two days ago I did tweet an observation I made that ‘a lot of php developers that say they do OOP in php actually do procedural programming using object constructs’. Im sure quite a number of php developers would know little if any about principles like SOLID, Design patterns etc..
Let’s not also forget that in design there are trade-offs. So it’s no different with php
Cool Article but I disagree with the IDE part… Dreamweaver is a fantastic IDE… One of the Best…
Dreamweaver has CS5 and CS6… use them before concluding,,,,
Thanks a lot and I am glad you liked it.
I used Dreamweaver a lot during my internship; it’s an awesome HTML editor and web design tool however it’s not a web development tool.
What dreamweaver did you use? It is a development tool… at least for web
Can you please tell me how Dreamweaver supports web development? I’ll be glad to know cos the last time I checked it was still for web design.
Your PHP programming experience is excellent. You describe many things from your experience.
Thanks a lot :)