When thinking about what makes an effective programmer I realized that as with any advanced skill you learn what are the best techniques to do something and you end up using them together as an atomic procedure. You no longer think of the best way to get information from a form and save it into database. You’ve brushed it up already and now you use it without thinking twice. You surely have a set of functions / objects to do it but that’s not my point. I’m talking about the patterns, not their implementation.
So how do I take a short cut so that I don’t have to waste my time with inventing my own patterns. I answered to myself: RTFM :-)
That’s how I found design patterns and Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (ISBN: 0201633612, Addison-Wesley Professional).
Surprisingly enough it wasn’t and is not going to be translated by major Czech publisher of computer related literature Grada. Costs for getting it from Amazon.com are discouraging so what now. (see Update below)
Refactoring: Improving the Design of Existing Code by Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts (ISBN: 0201485672, Addison-Wesley Professional).
This book was excellently translated by VladimÃr Lahoda as Refaktoring: ZlepÅ¡enà existujÃcÃho kódu (ISBN: 80-247-0299-1, Grada Publishing a.s.) so I was able to get it from a local library for free. Refactoring in general may not be always related to what I set out to look for however, this book is full of design patterns indeed.
You learn here how to proceed when you want to change your code without changing the program’s behaviour. You actually get a cook book of common design problems and step-by-step instructions how to solve them. Please note that it’s about design – not implementation or performance problems.
Here’s what I think this books brings apart from what’s its obvious goal.
Code Smells Hints
Because it lists problematic code and solutions to it you get to learn what a problematic code is and why.
You learn OOP as you read it
My blog is meant to be about PHP and this book uses Java for its examples. I don’t think it matters. The OOP principles behind it are the same.
Gives you arguments
If you ever had to lead a team you know what it means to know the right way but to miss the arguments to support your point of view. You know it but you’re unable to convince the rest of the team. Now you can use parts of the book.
Question 1
Do you rewrite your code to make it easier to read? Or do you do your best when you write it at the first time and when you need to add more features you just try to hack it as nicely as possible? What are your criteria for a project that is worth refactoring?
Question 2
How do you deal with refactoring from the project management point of view? If you are the boss then how do you promote refactoring – or how do you keep it within reasonable bounds? If you are the programmer then how do you persuade your boss that refactoring is crucial for your application in the long run? Maybe you don’t tell him at all and steal time for it like Robin Hood :-)
Update:
I just learnt that Czech translation of Design Patterns exists: Návrh programů pomocà vzorů (ISBN: 80-247-0302-5, GRADA Publishing a.s.). It is sold out though, and Grada doesn’t plan any reprints.
[…] Yet another blog about PHP Petr ‘PePa’ Pavel Refactoring: Improving the Design of Existing Code » […]
[…] Artima Software website seems to contain a lot of interesting materials on design. Here’s a list of links to all parts of interview with Martin Fowler. […]