Choosing a programming language and why is PHP still relevant in 2018

Ten years ago, PHP was definitely the better choice for the web. Things seem to have changed though. As a new developer, you are faced with quite a few options. First, there is Javascript that can now be used both in the frontend and backend. Then, there is Python which has seen a huge momentum. Ruby has always had his steady share. And there are many other languages coming out everyday. The junior programmer is left wondering what language should they learn as a web developer.

First, the question of what programming language to learn/use is a lot less relevant than a junior developer would think. The hard things in programming are organising your code, naming your variables, getting into the OOP/functional mindset, not repeating yourself and creating simple solutions. None of these are programming-language dependent. Once you get a hold of those, learning a new programming language only means getting over the nuisance of getting used to the syntax.

So how does one choose a programming language for a specific task? In some cases, the choice has already been made and you have to continue using the same language as you are not starting the project, but continuing it. In others, the client simply prefers a specific language because they worked with it in the past. But let’s assume total freedom of choice.

Programming languages by default offer very small building blocks, like if, for, while constructors. Then they offer libraries with small, contained objects and methods to work with things like files and databases. While usually they are very far away from what you have to build, the building blocks are small enough so with enough work, you can combine them to achieve any kind of result. Actually programming languages can be splitted into two different categories:

  • general languages, like PHP, Python, Javascript. They are not trying to solve a specific problem, but give you the tools to solve any problem. With enough work, that is.
  • domain-specific languages. While you cannot do anything you want with them, they can help you solve a problem in a specific domain much faster. For example, SQL helps you create databases, then query for data in a very efficient way. Mathcad helps solving math problems. HTML is a declarative language that helps you format web pages. CSS gives you a good way to style them.

You usually find yourself needing to use at least one general programming language, along with a number of domain specific ones. As a web developer, you will probably have to use HTML, CSS, SQL along with your general language programming of choice.

When it comes to general programming languages, you care mostly about what exists out there than can match the needs of what you want to build. I tend to categorize “what’s out there” in three distinct areas:

  • libraries. Code that allows you to use new methods and objects, without imposing a structure. For example, a statistics library will give you pre-built methods to calculate averages, means, deviations etc. You don’t need any specific code style to use them. Just search the documentation for what functions/objects are defined and call them in your code.
  • frameworks. They are more about helping you have a sane structure for your code. For example, a web framework will probably force you to use MVC, organise your files in a specific way, be mindful about security etc. They are invaluable for the beginner as you don’t have to go through the huge exercise of finding the best way to organise your code. They are great for seniors too, as they provide a very well documented way of working which helps board new team members faster, or even hire people with experience on the same framework, if popular enough.
  • full solutions. Think WordPress. You install it, then you have a full, working blog. You can use it as-is, or start making changes to suit your needs.

Given the above, the smart choice is to use the programming language that has most pre-built components for your needs. For example, it’s almost a no-brainer that if you are doing machine learning, Python or R are the better choice. That’s not really related to programming languages, but to the fact that Python has the most diverse, production grade libraries related to data analysis and machine learning.

Luckily enough, most languages do have frameworks. Once you’re done with learning the basic syntax, spend some time in learning the most popular/suitable framework for your needs. See how it feels.

This brings me to the last feature, full solutions, and slowly to the point why PHP still matters. Most problems are not that unique in the programming world. For example, I have been making a living in the last 10 years by mostly building e-commerce stores. While each store is unique, there is a lot that is common to all of them. So then it only feels natural to ask the question whether you can start from a “base” e-commerce store and build from there. And of course you can. And here is where PHP shines.

Mostly because PHP is almost as old as the modern web, there are a lot of full production grade solutions built with it. For example, most of the popular open source e-commerce solutions (Magento, Open Cart, Presta), are built in PHP. Then there is the hugely popular WordPress on which you can build a blog or any presentation/content site really. If WordPress looks like too restrictive to manage your content site, then there is always Drupal. Now since e-commerce and content sites cover maybe 80% of the sites that are out there, that’s a huge part. And of course, there are solutions for forums, mail clients, database admins and many others, but they don’t seem like the kind of things one would build nowadays.

Given that with PHP, you have pre-built solutions, it only makes sense to use them when the requirements match. There are a few arguments against it that I will try to defer….

  • “I can build a blog from scratch in X hours/days”. Yeah, “a blog”. But you definitely cannot build WordPress, with all the flexibility it offers.
  • Popular software like WordPress or Magento have a huge marketplace aroud them. You can buy a jaw-dropping theme for WordPress to have a great design for a few dollars. You can buy integrations with your preffered payment gateway for Magento at a small fraction of the cost to build it. Try that with your custom solution.
  • You can add more people to the team by simply searching for people with experience on the platform, very low learning curve.
  • “But I organise my code better, make it faster, more readable”. Most of the time this is simply not true. But even if it is, an effort a few orders of magnitude higher rarely makes sense business-wise.
  • “But Amazon, Facebook, Google, [Insert big brand here] do not use a pre-built solution”. This is totally correct. There is a point when maybe it makes sense to move to a custom solution. But that should be done when you are able to have a team of top-level developers and a huge budget. Trying to prototype a solution with not enough time and a team of juniors will end up in a disaster. Also keep in mind that some of the solutions used by the big companies are custom just because they started that way and never made the switch.

Overall, I feel comfortable with PHP as I can use software like Magento and WordPress to kick-start my efforts. It’s a no-brainer for me to use those when requirements match. What about custom solutions? I still prefer PHP. As I was stating in the beginning,  good software is about organising the code correctly. I can do this in PHP as well as I could do it in other languages. I can also use a decent framework (preferring Laravel) as well as any other. But I am faster with PHP and Laravel as I have used them for years, so I am lazy enough to not switch to something else just do implement the same thing differently. The only valid reason for which I use another language is when that language offers a great deal of libraries to help with the problem at hand, libraries that are missing/are inferior in PHP. And in that case, I only need to get over the syntax errors and language quirks. Most programming languages are similar anyway.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s