views:

135

answers:

2

I am working on a fairly large system developed by another programmer who no longer works here.

And since i am the manic serial killer who is maintaining it and knows where he lives.

But fun things aside, the system is kinda developed as a class system and kinda not and i have already setup a developer version and can deploy new versions pretty quickly.

  1. Do you have any tips regarding a partial move to a new model (i can not do a full transition, just don't get the time)
  2. Do you recommend any class names that i can leave in the system (without it looking like a hack) but will not clash with current class names (user, data, logging etc)

Thanks.

+1  A: 

zend has nice naming convention: http://framework.zend.com/manual/en/coding-standard.naming-conventions.html

They added Zend_ prefix to all they classes and that's how they avoid clashes with third party classes.

In my opinion every large project should implement similar naming convention, at least for core classes.

kodisha
The latest bata version of PHP has a simple namespace implementation. You may want to consider this in your project planning as prefixes will no longer be required. Namespaces are a much more "clean" implementation.
Nolte Burke
+4  A: 

Tip #0) Is the existing code really truly actually bad, or does it just not suit your personal preferences? If it's the former, continue reading this list. If it's the latter, take a few deep breaths, and spend at least a month or two getting to know things before you decide that you need to re-do it.

Tip #1) When you're coding, if you see something that's not right, fix it. This will take longer, but it will eventually give you productivity gains as the system gets more 'fixed'. If you really don't have time to fix it, do yourself a favour and add a comment like this: //TODO: rejig thing so it does x Later, when you have time, simply search your code for "TODO:" to get a list of stuff you need to do. You might also give them levels, like "TODO-High", "TODO-Medium", "TODO-Low". If you use Eclipse or Zend Studio for Eclipse as your editor/IDE, you can set it up to automatically find & flag these for you, in Preferences->Tasks.

Tip #2) An important thing to do if you hope to (eventually) transition to MVC is to separate HTML from logic. This means using templates. This task could take a long time, but once it's done, the rest of your transition will be much easier.

Tip #3) Try to establish conventions. Example: Controller & View names must correspond to the URL, and live in directories corresponding to the URL. URL To Edit Place 1234: /places/edit/1234 Controller File: /htdocs/sitename/controllers/placesController.php Template File: /htdocs/sitename/views/places/edit.tpl

Tip #4) Read 'getting started with' tutorials for the major frameworks: Zend, CakePHP, CodeIgniter/Kohana, Symfony. See if one looks better than another to you. Ask yourself why you like it. Will it work for you, or do you need to roll your own framework (doubtful). If at all possible, use an existing framework. It has already been bug-tested by hundreds or thousands of people, and that's time you'll save! I like Zend Framework myself, and it's particularly good for "transition projects" such as yours, because you can take it or leave it one piece at a time. I mean, you could choose to ONLY use Zend's View object, or ONLY use it's DbTable object. You are free to leave out as much of it as you like. This means you can gradually transition into a Zend-World at your own pace. EZ-Components works the same way.

Tip #5) Wrap classes that you use by extending them. For example, I use Zend_Acl, but actually use my own Acl class which extends Zend_Acl. This has two key implications: a) I can swap Zend_Acl for something else without changing my code, because it all refers to plain old 'Acl' b) I can modify how Zend_Acl works to suit my specific needs, because I can override whatever methods I like in my 'Acl' class.

Tip #6) Try to get buy-in from management. Explain to them that refactoring will actually save them money, because it will increase consistency & comprehensibility of code, which helps lowers the number of defects AND makes them easier to find & fix.

Tip #7) Try reading books on the topic, such as "Refactoring: Improving the Design of Existing Code" by Martin Fowler

lo_fye
Very good reply.
Ólafur Waage
I like your idea about TODO levels. Thanks! upvoted :)
Fedyashev Nikita