an entry from
Piotr's R&D blog
The Morning After
Here's a project proposal for a software documentation tool tentatively called "The Morning After". There are two assumptions you have to buy into: first, that well-done UML diagrams provide useful documentation for a system, and second, that typically developers will draw such diagrams only under duress. Still with me?
Adoption Issues
Current UML editors suffer from an adoption problem. Unless their use is mandated, few developers will choose to use these tools to do their design. I believe this is because they are too unwieldy for quick sketching1 and don't provide sufficient extra value to offset this deficit. Most agile processes recommend the use of pencil and paper (or whiteboards) for drawing informal diagrams, an approach that has met with some success. Unfortunately, the diagrams drawn this way are not always captured, and almost never updated as the code base evolves. Consequently, their use for documentation purposes is dangerous: an incorrect model is worse than no model at all.
There are two typical responses when people realize that things aren't working out, but still want UML diagrams for whatever reason.
- The big-bang approach says that you should do whatever you need to do to get your system working, then document all the code at the end, possibly with the assistance of some reverse-engineering tools. Though popular with procrastinating SEng students, it requires a lot of discipline to get right since documentation is not an inherently interesting activity for developers, and piling it on when they are burnt out at the end of a development cycle is often ineffective. Even with reverse-engineering, there's just too much to look through and correct all at once.
- The in-sync approach attacks the problems with tools, integrating UML diagrams tightly with the code, making sure that they always match (e.g. Together or EclipseUML). This is tricky to do right and requires that all developers be using the same development platform. Furthermore, in my experience, drawings diagrams and writing code requires two different mindsets; I don't want to be distracted with maintaining a diagram when I'm trying to solve a tricky low-level problem, or be distracted with generating correct code when trying to work out high-level design issues.
A Happy Medium
Here's a third approach, a scenario that I think hasn't been tried before. The developer sketches on paper and writes code all day, checking it in when it's stable. Overnight, our system analyzes the additions and changes, then reverse-engineers appropriate UML diagrams highlighting any changed areas (a visual diff). The morning after his coding binge, the developer comes in and checks his mail over coffee. The diagrams are waiting in his inbox, embedded with SVG and editable in-place. The developer looks over diagrams (perhaps comparing them to his sketches), makes some corrections, and puts the revisions back into the system to be used as the base for the next iteration of diagrams.
I think this system would combine many advantages:
- Editing a diagram requires much less effort than creating one from scratch. Furthermore, the diagrams are built iteratively, avoiding the big-bang effect.
- The editing process fits the developer's workflow and does not require him to install and (remember to) run extra software. Diagram reviews can be postponed by leaving them in the inbox, or the message dragged into a standard to-do list. Diagrams can also be easily annotated and forwarded between team members.
- The system provides some extra value to the developer, since reviewing the reverse-engineered diagrams may allow him to spot high-level bugs (e.g. introducing an undesirable dependency between packages, creating a reference cycle, etc.). The diagrams can also be automatically integrated into a project's on-line documentation (such as Javadocs), giving the team models that they can be confident are not stale.
- The application architect can keep track of the system's evolution in real-time, and step in early when reality starts to deviate from his design (possibly by modifying the design).
Getting There
The project involves many challenges:
- Creating an incremental reverse-engineering algorithm that will preserve the users' model and diagram edits as much as possible even though it's only fed coarse-grained difference information rather than fine-grained edits.
- A diagram selection algorithm that will heuristically decide which diagrams are likely to be most useful, since the system can't present more than a handful of diagrams to a developer every morning.
- A visual differencing algorithm to highlight the changes in the diagrams.
- A (simple) UML editor written in SVG, and a two-way converter between UML models and SVG diagrams.
Footnotes
1 New user interfaces based on tablets or electronic whiteboards might solve this problem in the future.
Comments
You might want to talk about how to deal with the multiple developers scenario from the beginning. That's more like the real development environment.
I will be able to do something for sure. Let's wait and see.
Is there anything available ? I'll be glad to test it and give you back my feelings about it.
Trying to keep UML diagrams in-sync with code is nearly pointless. Do not try to do that. It might be useful to keep some high level diagrams of the architecture of a system up-to date, but not on code level (which *is* the design).
I have come to use an UML diagram editor like this: development ususally happens in increments. First I study the relevant parts of the code and if needed/helpful I draw some UML diagrams about the relevant parts. Then I change the diagrams to include the new or changed functionality or I even go directly to change the code without first changing any UML diagram. Often I refactor the code, before changing it in the direction towards the new functionality (or towards fixing a bug). Those UML diagrams *mostly* are *intended* to be thrown away. I use UML diagrams to help me thinking about our software or discussing some aspects with others. And I create them as needed. But they do not have the value as the code. Just let them go out of sync! This is a natural process.
A key point for an UML diagram editor software is that it must definitely be very fast and very easy to use. I must be able to reorganize diagrams quickly and draw variants very fast (during my thinking). Otherwise, I will never use such a tool. For example, unlimited rock solid Undo/Redo is an absolute must (have you ever experienced that ugly feeling from an UML tool, when a box pops up stating that this operation can't be undone - uhhh? no thanks!) For that purpose, paper and pencil might be nice, but it is useless, because I cannot change paper-pencil diagrams, at least not a the speed and ease I need.
Or take an architecture discussion session with a team. Who uses those white boards? They are true evil (I used a very costly one that had an integrated scanner which produced fax quality like printouts of the whiteboard content - a bit better, but not what I needed).
Take a good UML diagram editor and a projector and draw the diagrams while the discussion flows. Immediately. I have been working in such architecture boards for months and we had to "clean draw" the diagrams after the sessions with an ugly monster UML tool and then bring the diagrams the next day to the new session. No thanks. That was one of the reasons I helped creating Cadifra UML editor.
And forget about things like code generation or automatic creation of diagrams from code. It is an illusion to think a tool could be built that can to that in a useful way. The main repository and the design *is* the code. Do not try to work exclusively on "another level". Code is not dirty. If it is, learn how to make it "less dirty" and understandable. By yourself and by others.
are actually useful. I may not have much time to help in the development itself, but I would love to be involved in design and testing where possible.