I have been a PHP programmer for a long time, it was the first web scripting language I learnt, and I have built some very cool apps, and it has served me well over the years.
However running a team who code in PHP has a lot of drawbacks:
- No de facto framework
- No coding standards
- Relatively slow benchmarks
Frameworks Rock
I personally love frameworks, who wants to code boring CRUD (create, update, delete) statements, build yet another admin, or yet another news management feature. Like all good programmers I am inherently lazy and hate to code the same thing over and over again.
PHP lacks a really good unifying framework, there is no de facto framework; Ruby has Rails, Python has Django, PHP has … CakePHP, Symfony, Zend Framework and Code Ignitor.
I have used all of the mainstream PHP frameworks:
- CakePHP – I like the syntax, but the docs are poor and performance is a real problem
- Symfony – I could not get my head around the workflow and it is very slow
- Zend Framework – does not seem like a framework to me, more a collection of libraries
- Code Ignitor – is the best of a bad bunch, and personally my favourite for PHP
These frameworks all compete with each other, instead of all working together to help build one PHP framework to rule them all.
Learning Curve
People love PHP because it is easy to pick up and get going with, you can write your first PHP script very quickly, and have something working in an afternoon. This works for good and evil, as there are so many people out there who code PHP who actually do not understand what they are doing. There is nothing inherently wrong with this, but this tends to mean that PHP has less coding standards.
On the other hand, getting Python to work is not as easy for a new developer and deploying a python site is even worse. Also as Python is a OO language it seems scarier to most new developers. I love Python as it just fits with my philosophy and I love the way that it FORCES you to write beautiful code.
Why Django
As I mentioned that as a PHP shop we have already looked at all the mainstream PHP frameworks and none of them in my opinion are good enough.
I had a look at Ruby on Rails, but the publicity and hype around it, coupled with the reported scaling issues made my wary.
My friend and fellow CTO Ben Philips over at Playfire, suggested that I check out Django. I had a read of the documentation and I was seriously impressed with the feature set. It was not the easiest learning curve there are a lot of pages to read on the site to get you up to speed.
I also started listening to the excellent podcast, this week in django, and I fell in love with the philosophy and elegance of Django.
Installing Django
Installing Django on my Macbook Pro was not an easy task, it took me a whole evening to get up and running; I had to tweak the MySQL python library and I needed to install XCode developer tools to get the Django built in webserver to work. This was not a good start for me!
Our First App
I did persevere through the installation and I was glad I did, the Django API is very elegant and for simple tasks very easy to pick up. I did have some issues managing images, but the Python Imaging Library helped me there. Also I had to get my head around the middleware stack, and the templating language. After a day or so I was ready to build my first app.
I wanted to really try something in a real working environment, so I decided to build the Oracle Acquisition App in Django. In less than two days the app was built including LDAP requests to the corporate directory, and SSO authentication into the Oracle unified sign on.
What I Liked
I loved the loose coupling of URLs, the encapsulation in models, lazy SQL queries, well defined code layout, adherence to DRY principles, admin out of the box and the powerful template language.
What I Disliked
Importing functions into the models and views was tiresome, the sometimes cryptic error message, no SQL query logging and lack of hooks for the admin (which had since been rectified).
The Future
Overall I love Django and I cannot imagine going back to PHP, the next step is for me to sell Django into the Company. It will take some effort of the part of the developers who cannot code in Python, but most good programmers can pick Python up very quickly.
There will need to be a migration process, but I will be slowly migrating all of our systems and future projects over to Django and will be recuiting a specialist Django developer soon. If you are a superb Django developer who is looking for a job in London (and you know a bit of PHP), then have a read of this post.
Good summary – this largely mirrors our organization’s migration from PHP to Django, which I also wrote up a few months ago.
Scot, many thanks for your comment. I read your excellent blog post a while ago, and it was extremely useful to see someone else’s journey from PHP to Django. I think we are going to see a big trend of people moving from PHP to Python/ Django unless the PHP world pulls together and creates one de facto framework. Personally I am loving Python, and would never move back to PHP.
This article has been picked up by the excellent podcast TWID: http://thisweekindjango.com/links/2009/mar/11/php-django-lessons-our-migration/. I am very thankful to them for their excellent podcast, it really keeps me up to date with Django commits, new features and the Django community.
You know, one thing I’m grappling with right now has to do not with the quality of Django but the side-effects of a comparatively small user/developer base. I’m under fire to get a really good survey system happening on a Django site, and there is exactly *one* survey app available. That one was broken in half a dozen ways, but fortunately developers responded quickly when I filed show-stopper bug reports. That saved my bacon, but still leaves us with just one survey system – and a pretty anemic one at that.
I know survey systems are complicated, but what I’m facing is the difficulty of explaining to a manager why we can’t just go back to using the PHP-based LimeSurvey, which is light years beyond what django-survey can do. So a rich ecosystem of available reusable apps is critical when it comes to convincing managers that Django is worth adopting. Right now I’m spending a lot of time on custom code to flesh out this survey app, which I wouldn’t have to do if we were in a PHP-based system. From the boss’ viewpoint, Django looks like something that’s wasting the organization’s time right now, because there are fewer pre-fab solutions for common problems, and the ones that are available take more tweaking/massaging to get running.
All of my talk about “clean code” and “highly object oriented” etc. doesn’t hold a lot of sway when they see me slipping deadlines because I have to build things myself that would already be built if we were using another platform.
I see your point, it is hard to show stakeholders the benefits if they are not immediately realised. However they should trust that you have the long term vision in mind, one of the key roles of the CTO is to set the long-term strategic vision, and make sure the company is using the best technology. For me Python and Django is the best technology. Adopting technology that is relatively new, will always mean more work in the short term, however the rewards will be much greater in the long term.
We are in a lucky position where by all of our code is bespoke, we do not use off the shelf tools, as most of the software we develop is so custom. That means we are in a great place to try new things.
The issue I envisage is supporting legacy PHP software we have developed, especially those that have a lot of frequent iterations and version branches. I think we will be using PHP concurrently with Django for a while until the legacy systems have faded out.
Sounds good so far. no matter how much I love PHP I would like to try Django. Especially if it will reduce number of servers to handle high load website.
> Importing functions into the models and views was tiresome,
this is a feature called namespaces. php doesn’t have those so you can’t have two functions with the same name being used in a website. thats a leak of php.
Thanks for your article. I am new at python and this will be a big help.
My pleasure Mike. If you have any questions please let me know via email or Twitter. Python rocks and Django is the perfect partner to Python.