François Constant logo

Python praise

April 2015

How and why I’ve switched from PHP to Python (for Web development).
This article is not a rant against PHP or any other programming language. To sum it up, switching to Python has turned out to be a great decision and I’d recommend to any developer getting too comfortable with a piece of technology to switch to something else.

First was the ignorance

At university, I’ve learned a bit of C, C++, Java, PLSQL, Smalltalk and more. There were no mean to learn yet another programming language. I was much more interested in understanding higher level concepts (UML, Merise, design patterns, etc.).

During my studies and at the very start of my career; I’ve mainly worked in PHP and I’ve learnt Symfony 1 about six years ago. I’ve never liked the PHP language itself but Symfony 1 is a great web framework and PHP has been getting better and better.

I did learn a lot while working with Symfony 1. About 3 years ago, we’ve started to use Symfony 2 as early adopters and despite its great architecture; I didn’t enjoy the transition at all.

Getting started with Django/Python

After considering Ruby On Rails and Play2; I’ve decided to try out Django on a small project. I wasn’t that impressed at first:

A Django application starts as an almost blank project:

Python can be “tricky”

Once I’ve figured out how to set-up my projects the way I wanted and had a better understanding of the Python concepts, I was rolling out tests and code faster than ever before. Almost four years later, I’m enjoying it more and more and wouldn’t go back to PHP, Java etc. unless forced to (for financial reasons…). The tricky points I have mentioned before are the main ones I have found so far… I’m not saying that Python is perfect but let put it this way:

I’ve built my very first website about fifteen years ago and Python is the only piece of technology I’ve ever trolled about.

What makes Python awesome?

Python greatness

It’s really easy to install packages and manage dependencies via PIP. When you start a second project, you might want a separate configuration, well, the virtual environments are easy to set-up as well !

Python drawbacks

What about PHP?

PHP has unfortunately many flaws, this article is an excellent sum-up: PHP, a fractal of bad design. And to keep this article balanced, here is a response from Symfony creator, Fabien Potencier: PHP is much better than you think.

In my opinion, the syntax is the main reason to love Python. The syntax is indeed extremely important when coding is your work. Developers are spending hours every day reading and writing code. Reducing the size of the code they have to produce and maintain has therefore a huge impact on their happiness and productivity.

In my opinion, Python has a relatively small user-base because:

1.Not taught at university => not used in companies => not taught at university => …

It’s our role as IT professionals to advise the best technologies to use. Customers would not usually require you to use a specific programming language, web framework, etc.

2.It’s expensive and risky to train the developers

Sure but it’ll be shortly profitable. More importantly, it took me less time to be productive with Django/Python than with Symfony2/PHP even though I had no previous experience whatsoever in Python. If you’re OK with your developers learning a new framework, you should be OK to let them learn a new programming language as well.

3.There are less hosting solutions available

There is plenty of hosting solutions available for Python. Of course, there are more options for PHP but it does not matter. You only need one hosting platform !

4.Python is too slow

Python clearly is not the fastest programming language out there but its speed should not be a problem. If a part of your application needs to be as fast as possible, you can link up Python with C++ and keep the simplicity of Python for 99% of your application.

Conclusion

If you feel like trying something new - which is probably why you are reading this article - do not hesitate and take the plunge. My only regret is to not have done it earlier. I still keep an open mind though, maybe I will use PHP 7 in April 2022 and I’ll sooner or later use Javascript (or something else) for the frontend.

Remark

PHP is not a language for beginners. PHP is a really permissive language, it’s therefore a language for experts. It’s also extremely easy to deploy some PHP code to production. This is the reason why it attracts total beginners as well. This large community of developers going from people learning coding via Wordpress to the engineers working at Facebook remains its main strength.