As an ArgoUML contributor I'm going to blog my activities here, so that they may draw interest by other developers or help other developers when doing tasks similar to what I've done. AND(!) the grand vision that makes an Argonaut what he is, TO THRIVE IN THE BIG DANGEROUS WORLD, TAKING THE Argo TO A GOOD SHORE ;-))

Wednesday, October 03, 2007

Uff! I finished the GeneratorCpp feature sketch

Previously I stated that I wanted to refactor the GeneratorCpp class. A good way would be to use some techniques I learned from Working Effectively with Legacy Code by Michael Feathers (2004), particularly, his feature sketches. Well, I worked hard to put the whole class under scrutiny and the result is very depressing (see bellow). Very different from the ones Michael has in his blog post.

Note that I used rectangles for functions and ellipses for variables. This is exactly the opposite from the convention Michael uses in his feature diagrams. My diagram is made in Draw and I had to use a A2 page so that everything could fit in a single one. I like this approach because, although it is harder to draw in the first place, when you have it you may drag things, group and ungroup, etc. This is important to identify and make clear the clusters that may be extracted from the monster with less pain. I put it in argouml-cpp doc directory, so, if you get curious, try it out.

GeneratorCpp feature sketch.

Picture 6 – Feature sketch of GeneratorCpp. Rectangles are for methods, ellipses for variables, blue for non-static and red for static. The yellow rectangle to the left denotes a cluster of methods that could easily be extracted, the yellow rectangle in the bottom center contains the methods I wanted to extract related to Associations, but, which are hard to extract from the class.

Don't misunderstand me, feature sketches are one more good thing that I will add to my tool box, but, they must be complemented with other things Michael talks about in his book, such as identifying responsibilities. This is more important if you are dealing with a monster class such as this. Nevertheless, the feature sketch enabled me to see the clusters in the class. Even more important, while I was doing it I reviewed the code in a way I never did before – actually this was the first time I looked at it from start to end. There are variables that keep pure processing state or context (generatorPass and actualNamespace), others that are mostly read and that keep configuration editable by users (e.g., indent, lfBeforeCurly, verboseDocs) and others that store processing results, which are used to generate code that deals with dependencies (e.g., includeCls, predeclCls, systemInc, extInc and localInc).

As a bonus I discovered some non-documented features of the generator that might come handy to solve some issues that are mounting up in the issues list. For instance, issue #22: provide a tagged value for user includes with angle brackets is handled by method addUserHeaders if the user places either in source_incl or header_incl tagged values the header name within angle brackets.

Reader Shared items