Design Article

UML versus Domain Specific Languages

Mark Dalgarno and Matthew Fowler

9/19/2008 10:19 PM EDT

With C++ and Java failing to deliver significantly improved developer productivity over their predecessors, it's no surprise that around 40% of developers are already using or are planning to use code generation approaches to tackle the problem of code complexity.

There are, by now, many cases studies of the successful application of code generation tools and technologies. Allowing developers to raise the level of abstraction over that supported by general-purpose programming languages is the best bet for development organisations wishing to address the productivity problem.

Although there are other approaches to raising the level of abstraction - such as framework evolution, or even programming language evolution, code generation, because it is flexible and fast, has the advantage of being able to adapt to new environments relatively quickly.

Here we consider the two most popular starting points for code generation; UML for program modelling [part of the OMG's Model Driven Architecture (MDA)] approach), and Domain-Specific Languages (little languages that are created specifically to model some problem domain).

As well as introducing both approaches, the aim is to offer advice on their usefulness for real-world development. We also ask whether they are mutually exclusive or if in some circumstances it can make sense to combine them.

UML and MDA
Experience of using UML as a modelling language is widespread and so using UML to express what is required in a system and generating code from that is acceptable for many organisations. 'Code generation' in UML originally meant a very low level of generation - converting classes on a diagram into classes in C or Java.

Experience has shown that this level of modelling does not give any business benefit when applied to complete systems. However, by using more specialised or abstract modelling elements it is possible to increase the amount of generation.

This approach was adopted by the OMG in 2001 as part of its MDA standard. MDA was developed to enable organisations to protect their software investment in the face of continually changing technology 'platforms' (languages, operating systems, interoperability solutions, architecture frameworks and so on). If the design and implementation is tied to the platform, then a platform change means a complete rewrite of a software system.

To avoid this, MDA proposed to separate 'the specification of system functionality from the specification of the implementation of that functionality on a specific technology platform'.

The specification of system functionality is a Platform Independent Model (PIM); the specification on a particular platform is a Platform-Specific Model (PSM). The PSM can be annotated by developers to provide advice or guidance for the final code 'text' generation step - which creates the source code and configuration files.

To reap the business benefits of this approach, the PIM must survive platform change and be reusable across platforms. The implications are twofold. Models become first-class artifacts in the development process, rather than being ignored after a certain point; if you change the PIM, the functionality of the delivered system will change.

The second is that code generation becomes important; mapping the PIM to the PSM by hand is costly and error prone, whereas automatic mapping to the PSM can significantly reduce the cost of a transition to a new or upgraded platform.

MDA defines a set of standards for transforming models that was finally completed in 2007. These standards are well supported in the telecoms and defence sectors, where there is a history of investing in development tools as part of large projects. In the commercial world, the lack of standards led to companies supporting the 'model driven' approach (MDD - development, MDE - engineering etc.) using a variety of tools to transform UML models into working systems " 'pragmatic MDA', as it was called.

The industry position of UML also means that developers can choose from a wide variety of vendors for their MDA tooling. Furthermore, vendors typically provide additional products based on the MDA approach, reducing the investment for an individual company to adopt MDA.

However, there are some issues in the use of MDA. First is the expression of detailed business logic. While 90-95% of a commercial information system can be generated from a UML model, there is a point where the business logic is not general and so not amenable to a code generation solution. There are two approaches to expressing the business logic.

The 'purist' approach is to model the business logic; one of the MDA specifications covers this approach. The 'pragmatic' approach is to leave holes in the generated application for the hand-written business logic; this is most popular where there is a rich, standardised development environment, like Java or C# and .NET.

Another issue is the low level of UML and the looseness (or generality, to put a positive slant on it) of its semantics: a common criticism is that UML is too big and vague to be effective. This assumes that the only 'code generation' possible is the very low-level code generation described earlier - the assumption is that UML can't express more abstract or specialised concepts.

But this criticism ignores UML's profile feature. 'Pragmatic MDA' vendors use this to specialise UML. To do this, they define profiles so developers can create models with a more specialised terminology and associated data. On top of that, vendors add their own validation to tighten up the UML semantics. The result is a domain-specific subset of UML if you like.

Using UML profiles gives as much expressive power as DSLs: stereotyped classes typically equate to the DSL terminology and stereotyped relationships are the same as for relationships in graphical DSL terminology. In other words, either approach can express concepts of arbitrary levels of abstraction.

There are two main problems with using UML with profiles to define new modelling languages: with current UML tools it is usually hard to remove parts of UML that are not relevant or need to be restricted in a specialised language, and; all the diagram types have restrictions based on the UML semantics.

For example, New Technology/ enterprise (NT/e) is in the process of building a graphical DSL for a novel middleware product. The key to this is being able to model methods as first-class model elements.

In theory we should be able to do this using action diagrams, but in practice there is too much other baggage that drags along with it. As we will see below, the DSLs are built from the ground up, so the modeller is not confronted with extraneous UML semantics or modelling elements.

Despite this, defining a high-level UML profile has historically been the best commercial approach to realising MDA. To produce a new profile is relatively cheap. On the marketing front, the installed base of UML tools and the understanding of the practice and benefits of modelling mean MDA products can be positioned as 'addons' rather than a completely new paradigm.


Next:




vocaro

9/22/2008 10:41 AM EDT

"With C++ and Java failing to deliver significantly improved developer productivity over their predecessors..."

This is a completely baseless claim. Java in particular is widely recognized as a more productive language than its nearest ancestors (C and C++). For example:

http://www3.interscience.wiley.com/journal/55001844/abstract
http://www.wellscs.com/robert/java/productivity.htm

Sign in to Reply



jeremy.ralph

9/25/2008 12:14 PM EDT

IP-XACT from the SPIRIT Consortium is an interesting XML DSL for SoC Design. On-chip addressable registers represent a pattern that is particularly valuable to auto-generate since this spans many different teams and languages in SoC development. Keeping all the dependent C/C++ firmware, VHDL/Verilog, verification code, testing, and documentation synchronized with the ever changing spec is a real challenge. Dedicated tools -- like http://spectareg.com -- automate register workflows to make them really simple and easy.

Sign in to Reply



rkpatil

9/26/2008 6:18 AM EDT

Adding to what Jeremy says, SPIRIT's latest spec is one more step in that direction. While it might be difficult to get one single language/methodology to model the specification of all systems, it is possible to have domain specific DSLs to capture various specifications and then use the different Generator concept to automate code generation. At Vayavya Labs we been able to demonstrate this concept to generate device drivers (OS specific functional code) for embedded domain/systems. For more info visit www.vayavyalabs.com

Sign in to Reply



Please sign in to post comment

Navigate to related information

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)

Feedback Form