Why is Python preferable to PHP?

Why is Python preferable to PHP?

The following are a few of the relevant reasons:

1. Python is better designed than PHP – PHP is not elegant as a language, although it is completely workable. That is not much of a problem in the short- to mid-term. Any developer who has a fair amount of experience in creating great software is likely to write good software in PHP. However, there are certain limitations.

To start with, PHP has certain idiosyncrasies that are weird. Beyond that, there are many things that are more nuanced and deeper.

From the point of view of a developer who is trained classically, Python gets a lot of things right in terms of being a programming language. This has much to do with the way in which reflection is implemented and functions are treated as first-class objects. There are many other things, many of which may appear to be of little consequence, which come together to help create code that is more elegant.

You will find it much easier to use Python to write great code, although it is not impossible to write good code in PHP.

Python has architecture that helps make it a well thought out, well designed and robust language. PHP, on the other hand, seems not to be so well thought out.

2. PHP has a short learning curve but it is Python which is better in the long-term – If you are a developer, you should consider what is likely to create the maximum value for you in the long term.

For instance, PHP has a rather low learning curve and is very easy to get started with. Working with it is fun and easy and you are likely to feel very productive.
However, once you are through with that initial phase, you have to think about the future. You would obviously want to work with a language with which you can form a deep, rich and long lasting relationship. In terms of that, Python fits the bill much better than PHP.

3.Python has a better web framework than PHP – Although conceptually developers would like to have choices, practically they like standards. If everything else is the same, they prefer that everyone works with the same libraries and frameworks. Python provides that mainly with Django, which is generally the de facto web framework choice in Python. Compared to that, PHP has Kohana, Symfony, CodeIgnitor and Zend.
In a way, competition is good. All of them are probably great frameworks, but since none stands out as a clear winner and the market is fragmented. Obviously, fragmentation is not good. It is particularly not good when it is associated with web frameworks.
The learning curve these days is more closely related to frameworks than languages. The richer and deeper the framework, the more you have to learn. There is an upfront cost for frameworks, but it translates into a lot of long term value.
However, if there are a number of platforms going around, the chances for any person using the same framework as you are lower. So, bringing some one new up to date takes longer.
As far as Python is considered, Django is the clear winner among web frameworks. So, if you bring an additional Python developer aboard, he or she is likely to have used Django before, making things easier for you.

4. Python is more readable than PHP – PHP is extensively documented and follows a classic approach. On the other hand Python makes use of indentation enforcements that are quite strict. Arguably, Python is not just more readable than PHP, but is more readable than most other programming languages.

5. Python has a simpler syntax – This may be because the syntax is simpler and the code easier to understand and write in Python. Another reason may be that when you write something in Python it is so elegant that you want to show it to others. That is generally not the case with something that you write in PHP.

6. Python offers simpler debugging tools which are available easily – Python has a big developer ecosystem and debugging tools for the language are available easily. Utilizing these tools is quite simple and you can take advantage of these without much of a hassle.
You require several such tools in PHP, whereas fewer are required for Python. The debugging tools you get in the Python downloader package are quite sufficient most of the time.

7. Package management is better in Python – Package management acts as glue between various projects. With its help, you can write, build and share packages in such a format that other developers can easily plug into other applications.
Package management is there in PHP, but there probably aren’t any code bases using it to the extent that PIP (a tool for installation and management of Python packages) does. It enables you to install, uninstall, upgrade and use a broad range of sources for internal and external libraries.
It is rare to find a list of all third-party libraries and the version numbers in use written in one file.

8. Evented codebases are available in Python – It is difficult to find anything in the evented space in PHP. Node.js does a good job in this field, but Redis bindings for Tornado and Tornado’s asynchronous HTTP client can help build low line count and low latency backends in Python, which function in an asynchronous fashion.
Using Python, you can build backends that perform authentication, query millions of rows in Solr and return JSON in a few milliseconds.

9. The Lambdas provided by Python offer an advantage over PHP – A Lambda is a subroutine or a function that is defined and called without it being bound to any identifier. It is a code block that can be passed around and executed later, once or several times.
The Lambdas flow freely within Python and are simple to create. So, developers like to use Lambdas when these are appropriate for the job. Until recently, there was only the ‘create_function’ available in PHP, which was not really a substitute for the Lambdas in Python. There have been changes made in subsequent versions of PHP and closure support is now available. However, many developers have been avoiding switching over for several years now.

10. Python is more ‘general purpose’ than PHP – PHP generally seems like it is more suitable for the creation of web pages. In contrast, Python is more of a general purpose language. In Python, you only have to select a simple web framework that provides the functionality that you require.

Conclusion: Whereas PHP appears to be easier to learn and become proficient in, Python helps you create more robust code. While PHP appears more appropriate for the creation of web pages, Python is more ‘general purpose’ and lets you work offline just as well as online

Comments

  • VIJAY | May 11,2017

    I’ll answer this one, but in the future you may want to make your posts clearer. Aside from the gist of your post I doubt anyone can understand your post.

    Python has been around for years, a fair bit longer than Java. It is primarily a scripting language, in many ways like PHP once was, which is why so many libraries exist for Python, and why there is still such a great divide between Python 2 and Python 3.

    For the record, Python isn’t as powerful as PHP. Python can be used everywhere, but so can PHP with the correct libraries. As someone who has casually worked with both languages I will say that Python is much, much nicer to work with. I’m a huge fan of Django, and it’s my framework of choice when working on stuff at home. PHP can be nice to work with, but I argue that most PHP projects are legacy projects, and most Python work is newer and as such is nicer code to work with.

    You can be a lot more expressive with PHP, so in that way it could be considered stronger, but given the sheer amount of crappy code out there I would probably call that a weakness.

    If you are a beginner and you want to start out in Web Development I would recommend picking either Ruby, Python, or ASP.NET. All three have/are strong frameworks, and by their nature will allow you to generate much nicer code. However, at the end of the day, these are tools to get the job done. Evaluate the job, and the tool will almost pick itself.

  • raj | May 11,2017

    If you were like me to have knowledge of PHP/MySQL & Java/JSP/MySQL & Java/Android, would you save time to learn Python 3 or latest???? would it make the life even a little easier?

  • veena | May 11,2017

    Before you decide checkout the Laravel PHP framework

  • vidya | May 11,2017

    The hardest part about Python it’s not Python itself but rather the server environment / deployment things. PHP is just save files and visit apache server, Python had a much steeper curve to learn all those things around.
    And then of course it’s the spacing issues which is hard to understand at first glance

  • Lenard Aszmondja | May 11,2017

    well while my first language was python, articles like these bring confusion in the land of coding. php has a lot better package management then python does.have you ever heard of composer? yeah.. its like aptitude for linux, and it is highly stansardised , python doesent have standards in the way that php does , check out php-fig. in terms of frameworks.. have you been living inside a cave? laravel beats even all. bigger comunity , long termsupport and afiliation to php-fig also its built on components, you can only use django as full frame! …also when building arhitectures, php supports type hinting, traits, interfaces and a lot more , python doesent.

  • Leave a Reply

    Your email address will not be published. Required fields are marked *