Python vs PHP

PHP has been designed primarily as a web language. It’s fairly simple to get it up and running – good news for new web developers. The language, however, is often described as limited and programming concepts beyond syntax are usually left to other languages.

PHP is often thought of as not so much a language, but more as a wrapper around other languages with memory management and a more flexible type system. There are many inconsistencies in PHP (e.g., in function names) and is of the “structure is optional” philosophy, this requires more discipline for programmers to code well. In a nutshell PHP is a language that encompasses all useful things in all other languages. Which, I guess, makes it inferior.

What is Python?

Python, OTOH, is a general-purpose language that is gaining popularity fast as a web language. It has greater applicability, but it’s a little more involved when it comes to getting it up and running on a web server. Python is certainly the more flexible of the two languages. It’s an ideal language for a new programmer, but not maybe not so ideal for a new web developer. However, if you already have experience developing web apps, this is probably not an issue.

What’s good about Python?

  • It is very expressive (little code does a lot)
  • The code is simple to read
  • If you are already an experienced programmer it will only take a few hours to get into the swing of it
  • Nice clean code
  • Real and consistent object system
  • Better documentation than PHP (though PHP is not bad)
  • More consistent libraries
  • BDFL (PHP is a mess!)
  • Good C API
  • Excellent web frameworks
  • Excellent desktop app support
  • Very cross platform compatible

Great Python features

  • list comprehensions
  • functions as first are first class objects (you can pass functions around just like any other piece of data)
  • functional programming tools
  • indentation determines scope (though this annoys some), which makes the code look nice
  • slice notation
  • powerful native data structures (lists, dictionaries, sets)
  • args and *kwargs
  • awesome standard library

What is good about PHP?

  • Easy to deploy on a webserver
  • Easy to integrate with HTML (good for small sites)
  • If you already know some PHP it may be easier to build your PHP framework if you want to build your app fast.

Some programmers complain that PHP does not support Functional idioms, brain dead functions, and name spaces. Though there are many work abounds that extends its functionality.

You can read more about these on PHP.net:

http://php.net/array_map
http://php.net/array_reduce
http://php.net/array_filter
http://php.net/array_walk
http://php.net/call_user_func_array (apply)
http://php.net/create_function (lambda)

It’s possible to write good PHP code but you have to exercise some discipline for it not to get messy.

Python Programming or PHP programming conclusion

Sometimes you don’t have time to configure the server to run a specialised application, you need something that can be installed and used right away in the shortest amount of time. Choosing PHP may be more of a business decision if time is of the essence. So it may come down to figuring out whether it would save time now and later to use PHP or Python.

SHARETweet about this on TwitterShare on LinkedInShare on FacebookShare on Google+Pin on PinterestDigg thisShare on RedditShare on TumblrShare on StumbleUponEmail this to someone

Heather Buckley is Director and co-founder of IT and business training providers Silicon Beach Training. Founded in 1999, Silicon Beach Training run public-scheduled training courses in their Brighton Training Centre as well as bespoke on-site courses worldwide. Popular courses include Social Media Training, Photoshop Training and PRINCE2 Training, which has recently been launched in Birmingham. Heather writes on the Silicon Beach Training blog with a focus on IT, Project Management and Social Media as well as offering Photoshop knowledge from her experience as a photographer.

  • great article. i hope you follow up with a more in-depth and analytical comparison as it applies to scalable web applications and modern/relevant web development.

    I am curious to see how python compares to php in terms of market penetration and enterprise usage (enterprises that run apache).