The language series: PHP
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 :
- 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()
- camelCase: getName()
- 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.