Some days ago I run over my Data Warehouse code with PhpMetrics, interesting and at the same time depressing since my code didn’t score well. When i took a closer look at the result I realised the lowest scoring code was other projects I incorporated in the Data Warehouse. I removed most of the ‘external’ code and evaluated my code again, I do not see this as an improvement.
My code after removal of ‘external’ code
When I had a closer look at the result, I found a lots of test code, often bad code still in the production code libraries, unfortunately it will probably take me a weekend of hard boring work to remove this code, but if I find time I will purge the test code. I was a bit surprised of the number of test shots in there, the number just grows with time.
Another interesting finding, most of the big reddies are code not touched for a long time, (most of the code is not touched for a long time), so it is stable and fairly complete code! However two of those red circles I have thought about rewriting since I’m not happy with the ‘code structure’, but doing that will take me a weekend per circle of extremely boring toil, so this will never happen.
I have put in some effort of study the underlying principles behind PhpMetrics, and that was pretty interesting, Halstead metrics and cyclomatic complexity, things I was/am just vaguely aware of, which is tools that can be used to evaluate ‘quality’ of code. Still I’m a bit sceptic, if a large piece of complex code executed thousands of times a day year in year out, never failed never changed comes out as bad code, I ask myself what is bad code?
I suspect my code suffers from PHP 4 (which was PHP when I wrote the code). PHP 4 was probably not the best of languages to write a language interpreter, with both lots of dynamic inclusion of code and dynamic interpretation (read eval). I probably have to adjust PhpMetrics to my PHP code, even though it feels like cheating when you play solitaire. But my Data Warehouse PHP code is a long way from a 'standard' PHP system.
There is no excuse for not using PhpMetrics, it is really a cool tool and very simple to use, it has already high lighted problems with my code. But before I can attack my code further with PhpMetrics I need to purge obsolete code, as it is now I do not see the forest for all the trees! Of course I want my code to turn up as green circles.
No comments:
Post a Comment