Techworld

Python vs. PHP: Choosing your next project's language

How I ditched the PHP Play-Doh and learned to love the snake

PHP and Python are two of the world's most popular Web programming languages at the moment, and naturally both have distinct advantages and disadvantages. However, at IDG Australia — the publisher of Techworld Australia — we've been working on moving from PHP to Python over the last 18 months or so. Although we're yet to regret this decision, it would be foolish to think that switching from PHP is a simple decision to make.

PHP vs. Python: Language popularity

There is no question that PHP is extremely popular; in fact, it's currently the most popular open source programming language. There are always PHP developers available and there are always PHP jobs around. Right now on Seek.com.au there are some 3790 PHP jobs in Australia. And this demand generally translates into a large pool of developers that can be tapped into when you want to expand your team.

Blog: Programming, creativity and open source

Python has never been that popular. However, counter intuitively, its lack of popularity compared to PHP can sometimes be a strength. Python developers may be somewhat rarer, but I've found they are often of much higher quality. While I'm sure there are some bad Python developers out there in the market, I have never had a job interview with one of them. I would love to be able to say the same thing about PHP developers.

PHP vs. Python: Language syntax

PHP has a very C-like syntax. Anyone who has been exposed to a C-like language gets it straight away. Curly braces and semi-colons work exactly as you'd expect and it feels familiar. I had no PHP experience when I got my first project based on the language. Barely two hours later I had read a small tutorial, found the bug I was looking for and a fix for my problem was being pushed into production.

Python isn't that easy. Making white space significant instead of using curly braces requires some adjustment to how you think about your code. This change will slow down people who have just switched to Python. With time this disadvantage goes away, however, as the Python syntax is usually extremely simple and in fact reads like pseudo-code.

PHP vs. Python: There's more than one way to do it

Many programmers when faced by a new project will tend to run ahead and code up a solution before thinking about what's required. Some languages pride themselves on offering as many ways as possible to solve problems. While PHP isn't as bad as Perl or Ruby in this respect, it will often offer many methods for you to do something. Python is not like that. If a task gets harder and harder to do, you know that you're going about it the wrong way. This will encourage junior developers to do things right the first time around.

PHP vs. Python: Web programming

PHP often feels like it's designed purely for creating Web pages, even if some people use it for other tasks. By default it's really an HTML template with code inserted in. Python, on the other hand, stands on its own two feet as a general purpose language. Programming for the web in Python involves choosing one of the web framework that gives you the functionality you want. If you're coding something different, however, it doesn't feel like you are working against the purpose of the language, specially as you can often use other general-purpose frameworks.

PHP vs. Python: Lambdas

Lambdas have long been an advantage of Python over PHP. They are so simple to create and flow so freely within the language that developers will want to use them when they are the right tool for the job. Until recently PHP only had the "create_function" function, which felt like a hack at best and a bad practical joke the rest of the time. This has changed in the latest version of PHP; there is now closure support. Will developers switch over, however? Some developers have now been avoiding this for years.

PHP vs. Python: Debugging and profiling tools

There are always promising links when you look for Python debugging and profiling tools using Google, but there always seem to be more available for PHP. The bigger developer ecosystem is an advantage here. That being said, I find myself reaching for this type of tool substantially less often when I'm coding with Python compared to in PHP. Maybe most people just don't need these kinds of tools when they are working with Python.

PHP vs. Python: But what does it feel like?

When listing individual reasons, it may seem like PHP has the upper hand. However, most people that I know that are comfortable in both languages will almost always choose to work in Python rather than in PHP. I don't know whether this is due to the simpler syntax and easier to write and understand code, but when I write something in Python, it's usually something I'm proud of that I want to show others. I can never say the same about things I write in PHP. This frame of mind can be explained quite simply. These two languages show up in the company cultures of those who use them. Facebook is in PHP. Google is in Python. Who do you want to be?

On a purely personal level, I'm left with the overriding feeling that PHP is like Play-Doh. You can make anything you want out of it, but at the end of the day it's still made out of Play-Doh.

Pascal Hakim is the director of IT and Development at IDG Australia.

Follow Techworld Australia on Twitter: @Techworld_au.

Join the TechWorld newsletter!

Error: Please check your email address.

Tags programming languagessoftware developmentpythonopen sourcephp

More about FacebookGoogleHewlett-Packard AustraliaHPIDG

Top Whitepapers

Twitter Feed

Featured Whitepapers