Use Modelling Software to Salvage Other People’s Code

93

If any real companies ever did get by with ready-made enterprise applications, those days are fading fast. Off-the-shelf software is now just a starting point for the modern enterprise. The onset of open source, combined with Rapid IDEs (integrated development environments) and DI (dependency injection) frameworks such as Spring, are increasingly taking software development full circle, back to the days of custom code and in-house applications.

Philippe DesfrayAgile development, DevOps and the ability to trial new application concepts by spinning them up in the cloud are speeding the trend for in-house development even further. Customization and innovation in business processes and the software that underlies them, are now core areas of competitive advantage.

For the developer, this means that the joy of working with other people’s code is becoming an almost unavoidable part of the job. For many of us, maintaining our own, long-forgotten code can be painful enough. Inheriting someone else’s can be downright agony.

An inherited code base can often be an impenetrable mess of last-minute hacks thrown together to keep management happy. Real-world pressures often leave little time for comments in the code, let alone full documentation and architectural plans. If your predecessor was bored or frustrated in the job, and if they were not well managed, the results can be painful in the extreme.

But, given the increasing prevalence of custom code, these painful results are rapidly developing into one of the most lucrative areas of work for the modern developer. The ability to sort out someone else’s mess, to grasp an untamed code base, ride it like a rodeo king and tame the beast, is becoming one of the most valuable skills in modern development.

First Step: Good Software Design

It is clear that there are many solutions to prevent the problem of scrappy, poorly documented code from occurring. Chief among them must be to enforce discipline and best coding practices amongst your development team. There is certainly no shortage of software that claims to automate policy enforcement.

More effective software design, the use of UML and other forms of software modeling, provide an invaluable starting point for long-term, in-house development. Models provide a top-down view of architectural rules, objects, classes and interdependencies. Not only does this simplify initial development and give a clear, granular direction, it also provides a clear architectural schema that can be used for ongoing extension, refinement and integration with the system once it is up and running.

However, hindsight and preventative methods are not effective tools for dealing with pre-existing code chaos. Modeling software, by contrast, can be!

Too Late? Reverse Modelling

The increasing sophistication of reverse modeling allows for top-down software models to be created retrospectively from almost any code base. This delivers an overall architectural model. Although the resulting model may not always make pleasant reading, it provides the information necessary to tackle the situation and a starting point, which is considerably more attractive than reading through thousands of lines of unfamiliar code.

It is possible to take raw code and generate a full class map of the code base with all its methods and interdependencies. You can produce architecture outlines including package diagrams with synthesized dependencies, and class diagrams. 

With the right solution Java programmers can produce full Javadocs and doclets.

Where code is well written, the architecture of an unfamiliar code base should become immediately clear. A poor quality code base remains poor quality, but through reverse modelling the developer is at least armed with a detailed map of the disaster site! Weaknesses can be pinpointed and corrected. From a solid software model it is possible to retrospectively impose architectural rules, to find and correct code that breaks those rules.

With powerful modelling software it even becomes possible to use reverse modelling to provide architectural analysis, to refactor models with full impact analysis, and even to generate code from refactored models.

Modelling software is no longer just one option as a starting point for custom code development. Simply checking the reverse modelling capabilities of your existing solution or the broad range of open source offerings available, reveals the power of software modelling as a tool for taming and managing other peoples’ code.

Phillippe Desfray, CTO of Modeliosoft, has been involved for the past 22 years in model-driven-development research, standardization, and tooling. Co-founder of Softeam, he is the inventor of the Class Relation OO model in 1990 and a key participant in the development of MDA through his book “Object Engineering: The Fourth Dimension” (Addison Welsey, 1994). He has been one of the main contributors to the UML standardization team at the OMG since its origin, and also contributes to many modeling language standardization efforts, including BPMN, SOA and others.

Philippe serves as VP for R&D at Softeam, is one of the key experts in the modeling and methodology fields and today is responsible for driving international R&D projects and leading the Modelio UML/MDA case tool development team.