tags:

views:

510

answers:

11

I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in experience to write things more robustly.

Is this worth the effort?

+4  A: 

Be sure to resist the Second-system effect and you should be safe.

Rewriting an existing project gives you a reachable goal. You know which way you are heading. But don't try to do too much at once.

stesch
+1: Don't overengineer. Just convert as quickly and simply as possible. Add features later/never and only after the conversion goes into production.
S.Lott
Also: this allows you to address technical debt. Which can be a good thing. http://en.wikipedia.org/wiki/Technical_debt
S.Lott
Technical debt is a good counter argument against the "Do not rewrite!" dogma. And it fits to my personal dilemma at work, where there is nobody around who really knows the old PHP code (from a designer).
stesch
+1  A: 

Is your aim purely to improve the applications, or is it that you want to learn/work with Python?

If it's the first, I would say you should stick with PHP, since you already know that.

troelskn
+14  A: 

You need to take some parts into mind here,

  1. What will you gain from re-writing
  2. Is it an economically wise decision
  3. Will the code be easier to handle for new programmers
  4. Performance-wise, will this be a good option?

These four points is something that is important, will the work be more efficient after you re-write the code? Probably. But will it be worth the cost of re-development?

One important step to follow, if you decide to re-write, make 3 documents, first Analyze the project, what needs to be done? How should everything work? Then put up a document with Requirements, what specificly do we need and how should this be done? Last but not least, the design document, where you put all your final class diagrams, the system operations and how the design and flow of the page should work.

This will help a new developer, and old ones, to actually think about "do we really need to re-write?".

Filip Ekberg
+1 . I am a pythonista but won't argue in Python favor for this one. Ekberg's answer is definitly the wisest.
e-satis
+2  A: 

Well, it depends... ;) If you're going to use the old code together with new Python code, it might be useful, not so much for speed but for easier integration. But usually: "If it ain't broke, don't fix it". Allso rewriting can result in better code, but only do it if you need to.

As a hobby project of course it's worth it, cause the process is the goal.

Stein G. Strindhaug
+2  A: 

Rewrites are very expensive: you spend a lot of time doing something which doesn't directly help you. Joel Spolsky elaborates on this:

Things You Should Never Do, Part I

You should do it if the benefits outweigh the costs; just be careful that you don't underestimate the costs.

daf
Don't listen to Joel Spolky on this. Make up your own mind. I made the mistake to listen to this and I have to maintain a stinking pile of PHP that makes my life miserable.
stesch
+2  A: 

As others have said, look at why you are doing it.

For instance, at work I am rewriting our existing inventory/sales system to a Python/django backend. Why? Because the existing PHP code base is stale, and is going to scale poorly as we grow our business (plus it was built when our business model was different, then patched up to match our current needs which resulted in some spaghetti code)

So basically, if you think you're going to benefit from it in ways that aren't just "sweet this is in python now!" then go for it.

Bartek
+1  A: 

If you are going to add more features to the code you already have working, then it might be a good idea to port it to python. After all, it will get you increased productivity. You just have to balance it, whether the rewriting task will not outweigh the potential gain...

And also, when you do that, try to unittest as much as you can.

Bartosz Radaczyński
A: 

Other issues include how business critical are the applications and how hard will it be to find maintainers. If the pages are hobbies of yours then I don't see a reason why you shouldn't rewrite them since if you introduce bugs or the rewrite doesn't go according to schedule a business won't lose money. If the application is central to a business I wouldn’t rewrite it unless you are running into limitations with the current design that can not be overcome with out a complete rewrite at which point the language choice is secondary to the fact that you need to throw out several years of work because it’s not maintainable and no longer meets your needs.

Jared
+1  A: 

As others have said, re-writing will take a lot longer than you think and fixing all the bugs and making use everything worked like in the old version will take even longer. Chances are you are better off simply improving and refactoring the php code you have. There are only a few good reasons to port a project from one language to another:

  1. Performance. Some languages are simply faster than others, and there comes a point where there is nothing left to optimize and throwing hardware at the problem ceases to be effective.
  2. Maintainability. Sometimes it is hard to find good people who know some obscure language which your legacy code is written in. In those cases it might be a good idea to re-write it in a more popular language to ease maintenance down the road.
  3. Porting to a different platform. If you all of a sudden need to make your old VB program run on OS X and Linux as well as Windows then you’re probably looking at a re-write in a different language

In your case it doesn't seem like any of the above points hold. Of course if it's an unimportant app and you want to do it for the learning experience then by all means go for it, but from a business or economic point of view I'd take a long hard look at what such a re-write will cost and what exactly you hope to gain.

A: 

One item that has not come up is the size of the current code base. Depending on how much code there is should influence your decision.

Joel Spolsky's argument to never rewrite is valid in the context of a code base the size of Netscape. Whereas a smaller code base code significantly benefit from the rewrite.

Gavin Miller
+1  A: 

I did a conversion between a PHP site and a Turbogears(Python) site for my company. The initial reason for doing so was two fold, first so a redesign would be easier and second that features could be easily added. It did take a while to get the full conversion done, but what we end up with was a very flexible back end and an even more flexible and readable front end. We've added several features that would have been very hard in PHP and we are currently doing a complete overhaul of the front end, which is turning out to be very easy.

In short it's something I would recommend, and my boss would probably say the same thing. Some people here are making good points though. Python isn't as fast as what PHP can give you, but what it lacks in performance it more then makes up for in versatility.

Robbie