MAY 15, 2018

Tags:

BackendPHPPythonWeb Development

PHP vs Python in-depth comparison from the business perspective

Written by: Ksenia Larina

Today we will be looking closer at two of the most popular programming languages used for server side development of the web applications: PHP and Python.

Although a huge part of online entrepreneurs who are only starting out with their first business tend to leave all the technical questions to professionals, we believe that understanding the basics of what’s hiding under the hood of your money-making machine is essential and can potentially save you a lot of time and nerves in future.

 

What is server side programming?

 

Every dynamic web-application needs two key components to run: a web-server and a client.

When we are talking about clients, we basically refer to a device on which your app is shown and interfered with.  

backend project

The entire data of your web-application is always stored on a server. That means, all the processing of your database happens on the server side, otherwise known as backend.

While languages running the client side, e.g. Javascript, are responsible for interpreting user’s commands and showing the updated information within the user interface, the real magic is happening on a server. Back-end developing is all about processing the databases.

Let’s say you run an online store and decide to add a new product to your catalogue. Once you add an item, a new object will be created in your database together with all the properties associated with it, like color, size, availability, will be assigned. So when you get your first buyers, this information can be processed using functions for searching and filtering these objects to match the requests of a user, or calculating the total for the items your customer had added to their shopping cart. In other words,

«All the actions performed to a database are processed by server-side scripts»

PHP: world’s okayest language

 

php comparison

The first thing you should know about PHP is that it wasn’t designed intentionally.

Back in the early 90s a Danish software engineer Rasmus Lerdorf designed a simple common gateway interface using C language, the sole purpose of which was to track views of his CV, and placed it on his personal web-page.

At that time Lerdorf didn’t realize that his so-called Personal Home Page tools would get so much attention from the developers’ community. In response to the public interest, Lerdorf began to extend his PHP tools adding more functionality until it grew into a framework for developing elementary dynamic web applications, and was later on released to the public.

If Charles Dickens was a programmer in 1995, when PHP went open-source, his famous opening to the Tale of Two Cities, might have been referred to this same event: “It was the best of times. It was the worst of times”.  

Once PHP went open-source, the rapid growth and continuous overwrites resulted in two things:

  1. What has once been a set of scripts evolved into the first sever-side programming language for developing dynamic web applications which had a built-in support of cookies, user-defined functions, worked perfectly well with the most popular databases (Postgres 95, MySQL, DBM) and was easy to switch to for anyone who was familiar with Perl or C
  2. The thriving community was so eager to push forward and influence the new technology, it began growing faster than it could. New features were arising in response to demand on the professional market, causing a spontaneous expansion and, as an outcome, flaws in the PHP’s design.  

Ever since it’s arrival to the world of backend programming PHP hasn’t really gone down, and all the articles with titles that go like «Is PHP dead already?» are nothing but clickbait. Here’s what W3Techs study says about the percentage of websites that use PHP as their server side language in 2018:  

 

is php popular

 

Nonetheless, such impressive statistics don’t mean that PHP is always the first choice because of it’s advantages over Python or other languages. In fact, it gets even more criticism than, probably, any other technology. Further we will be looking at a few reasons why it is sometimes impossible to separate the pros from cons of using this solution for your project.

 

PHP community is (too) large

 

php developers community

As we have already learned from it’s history, PHP has derived from a set of scripts written in C, which itself is widely considered to be a perfect entry point to computer science in general. Of course, it makes perfect sense that even though PHP has gone incredibly far in terms of performance and functionality from C, these two languages still share a lot in common, including syntax, function names, control structures and operators of all sorts.

No doubt, this lowers the entry barrier for every beginner who gets familiar with C, and makes PHP a prevailing choice for their further career in programming. Because it’s easy! Don’t we all love easy?

The good news:

Market is overloaded with PHP programmers. And we all know perfectly well that substantial supply always means that it will be easier to find what you’re looking for, and even better: it’s likely there always will be someone willing to do it cheaper.

Keeping in mind, that PHP is an open-source language, that has been around for literally decades, there’s probably an existing solution that your developer will be able to use even without any editing. But will this affect the speed of work? Yeah, it certainly will.

And don’t forget the lower bus factor. Meaning: if your best PHP developer gets hit by a bus, you will find a new one really soon. Or, in terms of people with a lighter sense of humor and higher morals, there are very few risks that the project you are working on gets frozen because one or more developers leave your team.

The bad news:

All these benefits can easily turn into your worst nightmare in case you run into a clumsy unprofessional developer who has grasped on the basics and went further on combining the existing solutions into one big mess.

Such approach may look much faster and cheaper, and maybe you will get a functioning product or a prototype, but on the long rung, it’s a no-go.

First of all, good luck maintaining that code. PHP is a very versatile language: there are probably 30 ways of doing the very same thing. Some of them are more elegant, some are less. Fast and cheap delivery usually results in lame code that is nearly impossible to read. What’s worse, if you don’t know how to test a developer, outsourcing team or a freelancer before hiring, you may end up with the same result, but waste more time and money.

Security may become even a bigger problem if your team decide to choose a library without thoroughly checking it. You may even unknowingly end up with a phishing website that will be sharing your users’ data.

 

Interpreter or Compiler?

 

is php interpreter or compiler

All the programming languages that can be understood by humans are called high-level language. The source code that engineers write in PHP, Python, C, Java or any other high-level language, needs to be translated into machine code, also known as binary code, that consists of 0s and 1s.

There are two ways to convert source code written by humans into a machine code that computers can comprehend: compilation and interpretation.

The main difference between these two approaches is that compilers translate your entire source code before the run-time, and interpreters convert it on the go, piece by piece, into bytecode which will be processed by a virtual machine’s engine.

 

Interpreter vs compiler comparison

 

CompilerInterpreter
MemoryCompilers do not produce intermediate code that requires additional memoryProduces intermediate code, additional memory is required
DebuggingWill show the errors only after compiling the whole program, making debugging slower and harderWill stop interpreting as soon as it runs into a bug, making it easier to debug
Multi-platform capabilitiesRequires different source code written for each platform separately.Interpreted bytecode can be read across the platforms.
Bug-probabilityLower. Compiler will check the syntax during the compile-time, and then again during the execution.Higher: errors can remain unknown until an end user accidentally runs into it. QA is advised.
DevelopmentSlowerFaster
ExecutionFaster. Code doesn’t need to be converted each time it runs.Execution is slower in comparison to compiled programs.

 

From this point of view, there’s no big difference between Python and PHP – they both originally were going to be used along with interpreters for translating their source code, but these days the line is much thinner and is often determined by what framework or third-party tool is used.

What you should take away from this is that interpreters are often feared because of only one main reason: it’s the execution time. They run slower, because each time the source code is translated and interpreted by virtual machine, and that takes some time.

JIT for PHP

 

just in time compilation

There is, though, an alternative solution that combines the strengths of both interpreters and compilers. It’s called JIT, what stands for Just-In-Time compilation and is otherwise known as dynamic compilation.

As you already know, interpreters convert the source code into bytecode eaten by virtual machines that know how to handle it. JIT does things a little bit differently: it compiles the bytecode into machine code on the go, or, in other words, just in time. This way, we still get the flexibility of development provided by interpreters and, at the same time, can enjoy the enhanced performance that can be compared to that of a static compilation.

Such approach definitely has its advantages. This is even proven by the fact that Facebook took a hold of it for their HipHop Virtual Machine (HHVM for short). This engine provides JIT compilation for PHP 5 at this moment, but unfortunately for all the appreciators of this VM, is going to seize supporting PHP by the end of 2018.

The reason behind this is that, as you may know, Facebook was initially written in PHP, but later on, they’ve begun switching to their own dialect of PHP called Hack. And, what at first was nothing but a spin-off from PHP, has now grown into a completely separate programming language. The one going its own way, which is in the opposite direction from PHP.

Due to the fact, the differences between Hack and PHP are nothing but a growing abyss, it makes sense HHVM developers are now choosing to dump PHP and focus on crafting the engine to work perfectly along with their designated survivor – Hack. This means, that by the end of this year there will be no virtual machines on the market that will offer JIT compiler for PHP.

And once HHVM drops the support, we’ll have to wait up until September 23d, 2021, when PHP 8 is released. Because that is also when we are promised to finally get JIT within PHP’s default interpreter, Zend Engine.

Disclaimer: if you’re running a small project that needs some page load speed optimization, chances are that you won’t ever need to worry about the availability of a JIT compiler for the backend language you’ve chosen. Most of the problems on smaller projects can be solved with minor adjustments, that a DevOps engineer can recommend. Such approach is much easier, cheaper and often shows much better results.

This means that JIT is only relevant to those who have already done everything else and are now fighting for their last 10% of the battle for the faster performance. If you’re only at the beginning of this path and don’t have a person on your team who could take care of optimizing the project for you, hire a qualified freelance DevOps engineer!

Why everyone hates PHP

 

why everyone hates php

 

A friend of mine describing his feelings towards PHP in the modern world used a perfect analogy that I’m going to share with you.

There’s a legend that a few decades ago, back in the blooming era of behavioral researches involving monkeys, some folks have come up with a so-called Banana Ladder monkey experiment, which apparently has never taken place, but is nonetheless a great story.

Here’s how the plot goes:

At first, there were 5 monkeys in an empty room which only had a ladder with bananas on top.

Each time any of the monkeys decided to go for those bananas, they all would get sprinkled with ice-cold water.

After several attempts, none of the monkeys would dare to go up the ladder, unless they wanted to be beaten up by the rest of the group.

Then, the scientists who led the experiment decided to switch one of the monkeys with a new one.

First thing the newbie did? Right, they tried to climb up and get their bananas. But, of course, they were immediately attacked by the peers who wouldn’t allow that.

Later on, scientists have substituted all of the initial group with the brand new monkey-members.

 

NONE of which would dare to go up the ladder, knowing they’d beaten up by their mates.

NONE of them, at the same time, have ever been sprinkled with cold water or seen this happening to others.

NONE of the monkeys knew why it is not allowed to go up the ladder to get the bananas.

 

Why would they beat up their mates then? Because they’ve figured that was how the things were done around there.

And now, why am I telling you this story? Because it perfectly illustrates why and how is php used in web development. It’s just the way things are done around the web. It’s an easy and obvious way. But not always the most rational one.

That doesn’t mean, though, that it should never be used. Here’s the list of perfectly good reasons to consider PHP for your project:

  • Prototyping. If you suspect that your MVP will only serve for demonstration purposes or your product will have to be re-written later anyways (which is quite common once you start scaling), and you won’t have to deal with legacy code later on
  • Small projects. Only if they are typical and have all the standard features, though.
  • Legacy code of an existing project.
  • You know it offers a solution for your specific requirements.
  • Your team consists of qualified PHP developers that will be better at it than any other technology.

 

ABC…Python

 

python comparison

The story of Python began back in the 1980s with a Dutch programmer Guido Van Rossum. At the time, he was working on ABC language together with a group of other programmers at CWI. ABC was meant to become a high-level language supposed to replace Basic for the computer science students and be used for learning and prototyping simple applications.

As it sometimes happens with passionate people, Guido took some of his work home and, inspired by some of the principles used in ABC, wrote an interpreter for another simple language that was able to handle the exceptions. He continued working on it and two years later, in 1991, published Python, named after Guido’s favorite comedy show Monty Python’s Flying Circus, for the first time.

Until this day, Guido stays the main person behind Python, which has become one of the most elegant, thought-through and well-designed server-side programming languages, that offers both high-performance and flexibility, that is required in high tech companies and products. Below we will review the most important features that make it such a good idea to use Python in web development.

Very high level, much readable

For this point, we will need a better understanding of the concept of low and high-level languages in programming. The level of a programming language is determined by the level of abstraction it has. At this scale, the most detailed language would be the machine code, which only has two binary options: 0s and 1s; while on the opposite side of the scale, the most abstract language would be a natural, human language, like English for instance.

Such definition basically means that the higher level language is, the better we, humans, can understand it. And while this idea may be a very basic attribute of programming languages, it does matter for business. Python is the one language that has a beautiful design and syntax, which makes it easier to read for a developer. Here’s an example of the Python code from GitHub that even a person without any programming background can read:

python code example

 

Can you guess what this program is just by looking at this piece of code? If your answer was “The Magic 8-ball”, you’re totally correct.

But we don’t love Python because of its looks. It’s what inside that matters. Inside your project, I mean. Because sooner or later, your business will need maintenance, updates and new features. Now, answer me this: how likely it is that from the very beginning and up until the end you will still be working with the same and only person who originally designed your product? Not so much, right? And that is exactly why the readability of the programming language is so important. If your code is well-structured it will be easier to maintain, adjust, implement new features.

“Easier means faster. Faster means less expensive.”

Object-oriented programming

This is when we start to see who’s the real pacesetter in this “Python vs PHP for web development” beauty contest.  

OOP paradigm supposes that your entire project consists of objects associated with attributes (properties) and methods (or procedures). To explain the concept in simple words, I will turn to a non-tech real-life example very often used for explaining OOP to beginners. Ladies and gentlemen, allow me to introduce you the coffee grinder.

object-oriented programming in simple words

 

Let’s say we have an object: a coffee grinder. This object is an instance of a class called “coffee grinders”.

We refer to a class as a sort of a template for an object, which we use for defining the attributes of this object (what size it is, how fast the razors are rotating) and it’s methods (functions it should perform, in our case – grinding coffee). Sounds quite simple, right?

Let’s dig into the three principles of object-oriented programming, then!

 

    1. Encapsulation

Encapsulation is a principle that protects objects by restricting access to their key components (attributes or methods), which are crucial for the object’s functioning, from other users. Think of our coffee grinder. You, as a user, only have limited elements of control of the object – it can be only an on/off button, or sometimes you’d also have a knob for adjusting the speed of razors rotating, or maybe a timer.  

Encapsulation in programming allows to limit the interdependencies between the objects and third-party access to the code.

 

    2. Inheritance

 

This principle ensures that any object based on another object inherits the same attributes and methods its parent class has. Such approach allows developers to reuse code without breaking the DRY rule.

Within our coffee grinder example, imagine that once you got a coffee grinder, the next thing you want is a coffee machine. Since you already have a grinder, you won’t need to code a new one. Instead, you can create a “coffee machine” class that will inherit the properties and functionality of a grinder.

oop class in simple words

    3. Polymorphism

 

Polymorphism means that same object can act differently according to the situation. In other words, depending on circumstances, our class will react in a specific way bringing us the required result.

In the world of the coffee grinders, this concept can be illustrated by two different types of machines: electric and manual. They both give us the desired result which is ground coffee. But thanks to polymorphism, we are free to choose the implementation that would be most appropriate for the conditions we’re in.

principles of oop

Can you choose Python or PHP for OOP?

Short answer: Yes.

Here’s what you need to know in terms of choosing PHP or Python for web applications that lie on the bigger scales. Python is entirely built around the principles of object-oriented programming. And while PHP does support OOP, it will be up to your developer to decide which programming paradigm to follow. And if you’re familiar with the Murphy’s Law, you know why such open choice can be dangerous. If you’re not, remember once and forever:

“If anything can go wrong, it will”

So, the real question is whether you are ready for the pain that may come together with a decision of a PHP developer who thought he could handle the project which requires OOP using procedural paradigm. Decisions like that become a pure nightmare material, transforming your business into an addict dependant on constant, expensive in terms of both time and money, code overwrites that will only make the situation worse with every “fix”.

For better understanding, let’s compare procedural vs object-oriented approach applied to the same typical situation. Imagine, you are the owner of a real estate agency and hire a developer to create a website, consisting of two major web pages: one for you to create and enter all the data for the listings, another for your clients that will be showing this data.

Since your agency is focused on selling apartments and houses, these will be the two types of estate you have on your site. While both apartments and houses have some common traits, they also have a couple that differ:

 

ApartmentsHouses
Square ft.
Bedrooms
Price
Doorman 𐄂
Garage space𐄂

 

If you’re dealing with a developer who chose the path of procedural programming, he will immediately start coding the functions for processing the data input forms and display for both apartments and houses separately.

With OOP the solution will be a bit more graceful. At first, we will have to create a parent class – Real Estate, which will contain only the common attributes: “Square ft.”, “Bedrooms” and “Price”. For each of these attributes, we will also create data input and output methods. After that, we will create two child classes: Houses and Apartments. While these will inherit all the properties from the parent class, we can also add their unique attributes such as “Doorman” and “Garage space”.

Now, if you’re 110% this is everything your business will ever need, and there will never be any additional features you’d want to see on your website, either way will be fine. And maybe, PP will be even a faster and less expensive option.

But let’s say, you haven’t considered all the odds. Here’s how it will go in case you ever want to add something new or fix some bugs:

 

ProceduralObject-oriented
Plot 1 – you decide to start selling warehouses which have their distinct features like «Height» and «Power supply»Code all the functions and forms from scratch.Create class «Warehouses» which inherits everything needed from «Real Estate», add unique attributes.
Plot 2 – let’s separate new properties from the established!Have fun coding new functions to all the objects!Just add new attribute and methods to the «Real Estate» class, others will inherit.
Plot 3 – your agency grows, and you need to be sending a notification about new estates all your salespeopleAnother round of adding code to all the functions for Houses, Apartments, and Warehouses!Add a new feature to the parent «Real Estate class
Plot 3.1 – there is a bug with the notifications, they show the wrong price of new objects in your databaseGo fix all the functions.Fix the code of the parent class.

 

I guess, for situations similar to this one, the winner is quite obvious.

Python for AI and machine learning

ai data science python frameworks

 

Perhaps, the most important advantage over PHP is it’s potential for machine learning and AI. There are a few reasons behind it:

 

  1. Python is a general-purpose language that can be used for different kinds of programming contrary to PHP which is used for web developing
  2. Its’ dynamic interpreted script provides opportunities to build prototypes faster
  3. Low entry-barrier, easy learning, and well-designed structures attract beginners that wish to focus solely on machine learning, AI and data science
  4. A number of frameworks and libraries for machine learning available for Python can’t be compared to any other language

 

Here’s just a glimpse at most popular Python frameworks and libraries for machine learning:

And even if you think your business can’t benefit from AI tools, you might want to take a second thought on that one. Because, personally, I don’t know a single person who wouldn’t want their daily routine to be fully automated, so they’d have more time to focus on their strategic tasks.

 

Python vs PHP performance from the business perspective

php vs python for business

Before making an important decision about the tech stack you will be using for your project, you have to consider all the available information. Never make this decision from down up. You don’t want a project that will suit a specific programming language or a framework. You want the technology that suits your project.

 

We’ve done our best to list all the important traits that distinguish PHP from Python to make this decision easier for you. And here are our final thoughts on this matter in a side by side PHP vs Python comparison table:

 

PHPPython
CommunityMany developers, not so many up-to-date solutionsFast growing, very involved, new solutions appear often
TypingDynamicStrong dynamic
Interpreted or CompiledInterpretedInterpreted
JITN/A until 2021Available in PyPy
Language purposeWeb developmentGeneral purpose
OOPsupportedOOP-centered
AI and machine learning potentiallowhigh
Readabilitylowhigh
Debuggingslowerfaster
Hosting supportvery commonless common
Securitypoorgreat

 

Overall, our general advice would be: don’t overthink it.

 

If you’re only just starting out and don’t know which technology you should go with, pick the one that will allow you to build a prototype of your product, or an MVP as fast and cheap as possible.

In most cases, it may be even not necessary to code a web application from scratch and would make much more sense to start off with a website built on Shopify or WordPress.

Such approach will give you an opportunity to test your ideas before investing tons of your time and money into it, and maybe even get your first revenue, which you will be able to reinvest into a more sophisticated product.

Just be sure to remember, that when you’re in online or innovative business, all the tech decisions equal business decisions and have a direct influence on how successful your company is. Therefore, think twice, be lean, don’t spend money you don’t have, don’t hire people you won’t need on your team constantly.

And if you already know which option you want to go with and are eager to know how much such project would cost you, or you are only getting lost in the ocean of information and need a second opinion from an experienced developer, request a quote from CodingNinjas. We will get your estimate in less than 48 hours and find you a freelancer, or even a whole team.

Quit putting things aside for later and wasting your time on over-thinking. Start acting already!

1 Star2 Stars3 Stars4 Stars5 Stars (15 votes, average: 3.87 out of 5)
Loading...

Vetted freelance developers ready to start working on your project today.

get a quote in just 15 minutes

You might also like

FILL OUT THE FORM
TO GET A QUOTE!
$149monthly plan
The Freelancer
  • 5 developer hours per month
  • Additional development time at $29/hour
  • Unused hours roll over up to three months*
  • Unlimited support 7 days a week
  • Cancel anytime
$495monthly plan
The Professional
  • 20 developer hours per month
  • Additional development time at $25/hour
  • Unused hours roll over up to three months*
  • Unlimited support 7 days a week
  • You can cancel at anytime
$1399monthly plan
The Business
  • 60 developer hours per month
  • Additional development time at $23/hour
  • Unused hours roll over up to three months*
  • Unlimited support 7 days a week
  • You can cancel at anytime

For 90 days from the date of each payment.