From PHP to Python

Before I wrote my “Dear John” letter to PHP the other day, I had largely decided to move to Python as my primary tool. I had been on the fence for months about choosing to pursue Ruby or to follow the Python path. I purchased a book about each and did quite a bit of other research as well. The fact that there are so many passionate flamewars about which is “better” was actually quite helpful. It proved a suspicion that I had formed during my research: it didn’t really matter which one I chose. There would be nothing to argue about if one were clearly the best language to learn. There isn’t a whole lot of debate about which is better for web development: Python or Lisp, Ruby or Delphi? Since Python and Ruby both are very suited to web development, it really boils down to personal preference. Having experimented with both, here is why I chose Python. Your mileage may vary.

Similar purpose, different philosophy

I primarily dinged PHP for not having a what I call a guiding philosophy. There seems to be a disconnect between Zend Technologies and the PHP community and that lack of focus is crippling PHP. In some ways it reminds me of the relationship Red Hat has with the OSS community. Neither seem to completely trust each other and there’s friction when deciding on how to move a project forward. Almost from Day 1 (well, make that PHP 3.0) Zend seems to have focused more on building a language around a business rather than the other way around. Trying to be everything to everyone, focusing more on the quanity of installations rather than security, and borrowing features rather than innovating isn’t a recipe for success in the world of open source. That sounds more like how commerical software is churned out.

I find both Python and Ruby are far more community-driven and focused. However, the communities both have distinct, and dissimilar, philosophies. Ruby is the kindergarden teacher who gives each of her students the big, 64-color box of Crayola crayons. The children are given the freedom to draw a dog in whatever manner they choose. In Python school, students assigned only four crayons: red, yellow, blue, and black and are given step-by-step instructions on how to draw the best dog possible. Now, I’m not saying that Python has less features than Ruby. The Python community simply has a more formal structure and and a greater focus on the nuts-and-bolts of improving the language as a whole. Ruby is less inclined to define specific guidelines and prefers to give programmers several options, allowing her/her to pick and choose.

Ruby’s community more closely maps to my personality (hey, my company is named RightBrain Networks). However, I am finding myself involved with increasingly larger web projects, both solo and with other developers. When developing a large project, even solo, consistency is paramount. The less time I spend figuring out what the other guy’s code is supposed to do (or what I wrote last night at 3am), the better. It also saves me from having to research which one of the choices is best in my current situation. Ruby subscribes to the “Principle of Least Surprise”, meaning that the language ought to bend to the programmer. However, I find myself preferring Python’s approach, which is that if the language already knows the best approach, then I should bend to it. If we all agree that the “Python Way” is best, then we don’t need to adapt to each other’s individual styles. Hence, larger projects are both more efficent and fun because I can spend more time writing code than deciphering/researching it.

Is Ruby a one-trick-pony?

I’ve met more than one person who’s wanted to learn (or wanted to hire someone who learned) “Ruby on Rails”, not knowing that Ruby existed a full decade before being attatched at the hip with Rails. I’ve played with Rails and am quite impressed with its capabilities. However, what happens once the honeymoon is over? It seems like a risky career move to jump from buzzword to buzzword. I know that Ruby exists outside of the Rails, but I’m not sure how practical it would be to learn Ruby if I wasn’t jumping on the Rails bandwagon.

Both Python and Ruby have been around since the early/mid 90’s. Which has been better adopted by organizations that may wish to hire me? On Monster.com there are currently 347 job listings with “Ruby” contained as a keyword. Of those 347, 95 don’t specifically mention “Ruby on Rails”. There are also 923 listings looking for someone with Python experience. While not strictly scientific, I feel that indicates that Python stands on its own merits, apart from its web frameworks, moreso than Ruby. Again though, I’m not talking technical points, which I feel both are very comparable. However, I would argue that employability should be given more weight than technical minutia when planning a career.

If the Rails framework started to take a direction I didn’t care for, I don’t really have many options. My skills wouldn’t be very portable. However, by learning Python, I can pick from several different, well-known frameworks: Django, TurboGears, Pylons, or web.py. Or if I even wanted to get out of web development, Python is used in many other applications.

Conclusion

While I like certain aspects of Ruby more than Python (as a newbie, the whitespace thing is still driving me nuts!), I feel that Python is overall a better fit for me. It’s greater emphaisis on structure will help make developing and maintaining large projects easier. And because both the language and the jobs aren’t so intimately tied to one framework, my skills are more portable and future-proof. I’m sure there are people out there that will disagree with my analysis, so if you’re trying to decide with path to take, please take the time to play with both of them and ask advice from both camps. Thanks for reading.

14 Replies to “From PHP to Python”

  1. The whitespace thing is driving me nuts too.

    You said you are going with Python – are you going to use a established framework(like django) or and you going to make one from scratch?

  2. I’m ambitious, but not quite *that* ambitious.

    I’ve installed both TurboGears and Django thusfar. I’m currently experimenting more with Django, but will probably try TurboGears again after I’ve figured out Django.

    I’m going to wait until after I’ve become more familar with Python before I delve into the other frameworks though.

  3. To quote you:


    “However, I would argue that employability should be given more weight than technical minutia when planning a career.”

    If you serach for PHP jobs on monster.com or on any other job website, you will get thousands of job listings.

    so how does ur comment justifies your transition from PHP?

  4. Sure, but I already know PHP; it’s what currently pays my bills. I don’t doubt the fact that PHP is more widely used in web apps than Python. However, I’m trying to look further down the road.

    Even with Cake or other MVC add-ons, I don’t see PHP being used in large, complex web apps for much longer as the Python/Ruby frameworks mature and grow in popularity. The difference between PHP and Python is the difference between ASP classic and ASP.Net. Having created some pretty large web apps in ASP in my career, moving to ASP.Net was like mana from heaven. I want that same experience again, but with open source.

  5. PHP is a crappy language but works well for simple pages
    Python app server is powerful but slow, exceptions blegh
    Ruby on Rails combines those two worlds
    Java serverlets are, well, it’s java, you know the rest
    C starts to sound good, then you remember it’s public facing and you’re *bound* to have a bug in some parsing code.
    Lisp is still on the radar but how long until you know if it’s for you or not ?
    Haskell – elegant with ugly monads
    Limbo – C like with no pointer arithmetic but needs a VM unless you want to dedicate a machine to it, if you can get the drivers etc.
    .NET nice runtime, lousy host

    For your personal development, go with Python. It will lead you to new places from where you will see a better landscape.

  6. Python’s indent convention is the worst idea since C++. Ruby’s syntax is simpler and more intuitive.

    IMO, Ruby is a “better” language. For web development. Using Rails, of course.

    Python, however, is a great cross-platform language for deskop development. Pick your UI layer from Qt/PyQt, wxPython, Cocoa, etc. Build a core architecture with Python. Its a great recipe.

    Given a choice and the project’s requirements, I’d pick RoR for the web side, and Python for the desktop.

  7. I use both frequently. I find Python to have more third party libraries and to be better suited to Windows development, but I actually enjoy writing Ruby more. When I need a quick, immediate solution, I normally use Python, but when I have time to experiment, I normally use Ruby. Either way, both are great choices… best of luck to you!!!

  8. I’m afraid you don’t have much experience with enterprise companies, do you?

    “I don’t see PHP being used in large, complex web apps for much longer”

    What are you smoking? PHP is JUST starting to come into it’s own in the enterprise world. Companies just don’t decide “hey let’s switch to python because our developers are bored”. PHP’s enterprise future is brighter than ever now. IBM is pushing it to all it’s as400 machines and corporate servers.

  9. Jim,

    Yes, I’m a former corporate America refugee. Though it was more on the network/systems side of the IT spectrum.

    Granted, that statement was just SWAG on my part, PHP is used by Wikipedia, Digg, OnForce.com, and a host of other highly visible companies. Even YouTube uses it on the front end (backend is Python though).

    But… all these companies use PHP almost solely because that’s what their developers know. It’s not because PHP is more cross-platform than anything else (it’s not), it’s not more maintainable (ugh), and it’s certainly not because it’s a speed demon. It’s used by the big guys because it’s 10x easier to find a PHP guru than it is an equally experienced Ruby or Python web developer. This is a non-trivial matter when picking a platform (esp. for large companies), in fact it outweighs every other consideration: licensing costs a close second, performance a distant third (“we’ll just throw more hardware at it”).

    As Ruby and Python gain more momentum in the web development arena due to their frameworks, both more jobs and more qualified canidates for those jobs will show up. I strongly believe that PHP won’t be the default OSS web development platform for large projects for much longer.

  10. tubby,

    Thanks. Yeah, I find the Python vs. Ruby holy war kinda stupid. As I mentioned in this post, I really think it comes down to personal preference. I eventually would like to learn Ruby too.

  11. Web 2.0 loves PHP: YouTube, Friendster, Flickr, Digg, Wikipedia, Technorati, Facebook. With many billion pages served per day, they are all very very big web applications in the world today.

  12. Having found your blog through a post about php, I’m glad to see you’ve switched. Having developed web apps in php with mySQL for a few years, I was frustrated with the embedded html approach. Python in contrast is amazing – I find that after reading Learning Python, I’m creating beautiful pythonic code. And with facebook’s recent php code leak, more companies will shift towards python or ruby, and more php programmers will be trying frantically to update their resumes.

  13. Good luck and welcome to the python community!

    We are currently re-writing all our systems to python from PHP and the same happens all over.

  14. Its funny what people learn in the schools now. The harder it is to learn or use a language the better it is.??? Java sucks in this respect. Projects take forever because the complexity right from the start. You can develop perfectly mantainable code in PHP, even without the use of a frame work. As long as you dont start puuting all the database code in the web page you will be fine. I use classes for everything and my html code is basically uninterrupted. I use php for large and small projects and it works great. I have to laugh when I see the java developer scratching there heads at things that should be easy but the whole language, the app severs and structs make them hard. If you feel good to work on a language that make thing hard. Then you have some serious problems.

    A good language is suppose to help you to the job quickly. It does not have to be a competition to who comes up with the harder solution. The first thing they told me in school was to KISS(keep it simple stupid). PHP is a simple and powerfull language

Comments are closed.