IEEE Software ModelTalk WhenEverythingisaDSL
IEEE Software ModelTalk WhenEverythingisaDSL
net/publication/220091931
CITATIONS READS
24 572
4 authors, including:
Lior Schachter
The Open University of Israel
7 PUBLICATIONS 50 CITATIONS
SEE PROFILE
All content following this page was uploaded by Atzmon Hen-tov on 23 February 2014.
ModelTalk:
When Everything
Is a Domain-Specific Language
Atzmon Hen-Tov, Assaf Pinhasi, and Lior Schachter, Pontis
L
arge-scale, complex, back-end business applications such as telecommunications
ModelTalk, a model-
software constitute a highly competitive and demanding market. These appli-
driven software
cations feature deep integration with other business and operational support
development systems. They must be tailored for each customer, and the customized systems
framework, supports must meet strict extrafunctional requirements, commonly called “telco’s five 9s” (99.999
the creation of percent availability). All this, combined with the need for an agile development process
product lines by with a short time to market, presents a software development and business challenge.
using domain- One way to cope with this challenge is to con- claratively implement concrete requirements.
specific languages struct a software product line.1 You establish an When considering broad adoption of DSLs in
initial collection of rich, generic, reusable software the development organization, you should antici-
pervasively at components. These shared assets of the product pate and carefully plan for increased DSL usage.
the core of the line are then methodically assembled, custom- You wouldn’t want to end up with numerous,
development process. ized, and fine-tuned for each production system. disconnected DSLs, requiring your developers
But you must also have a reliable, concise customi- to master many concrete syntaxes, development
zation process to go with your product line. Such styles, and tools. That might lead to a great cogni-
a process is necessary for performing pervasive tive burden, ironically inhibiting the same agility
modifications to the shared assets quickly without you were trying to achieve by establishing a DSL-
compromising their robustness. based development process in the first place.
Model-driven development (MDD) is often the Once you transition to DSL successfully and
development process of choice.2 This is where do- manage DSL scalability wisely, you’ll discover that
main-specific languages (DSLs) enter the picture.3 much of your software development effort has suc-
DSLs possess two, highly desirable characteris- cessfully shifted from writing imperative code to
tics. First, they facilitate variability management writing declarative composition and customization
in MDD by providing the means for express- scripts. This is the case with ModelTalk, a DSL au-
ing customization concisely and often declara- thoring and execution framework.4
tively. They also support a producer-consumer
development process, in which one group of devel- Approach
opers defines a DSL around components and con- The ModelTalk motto is “Everything is a DSL.”
cerns, while other developers use that DSL to de- DSLs can be extended and composed. They’re
Figure 1. The ratio of Java (purple) to DSL (gold) code by architectural Textual DSLs
layer in a product line of business support systems. Most of the In ModelTalk, DSLs are textual rather than graphi-
assembly and the customization of products is done with DSLs. cal. The concrete syntax for DSL code is XML. The
ModelTalk core provides a general-purpose lan-
guage with abstractions (Class, Property, and so on)
Feedback
and syntax rules for defining DSLs. A developer
DSL and Java integrated Runtime creates a new DSL by adding new and constraining
development environment platform existing class properties to better describe the do-
DSL Executable DSL execution
main-specific concepts and terminology. In XML,
DSL sources
processors DSL code engine these are expressed via tag names, which constitute
the domain-specific terminology.
Constrains Conforms
Particular assets
Customization
Product B
Product Z
parts). A refactoring tool for DSLs is also avail-
able, and changes are propagated to Java when Subscription HappyHour …
necessary.
Interpretive Approach
Business
DSLs in ModelTalk are interpreted; they don’t Goods Promotion Eligibility
need to be transformed into Java (by a code gener-
ator). At runtime, instances of DSL classes are in-
Shared assets
stantiated and used as meta-objects for their corre-
Platform
sponding Java instances through a technique called
Persistency Data-model
(model-driven) dependency injection.6 The DSL
execution engine is ModelTalk’s runtime compo-
nent, implemented as an inversion-of-control
container and a dependency injection framework
Core
Meta DSL Specializes
(in the Spring framework style). It can run either Contains
inside a standard J2EE application server (for ex-
ample, JBoss) or inside a lightweight container.
The execution engine’s primary responsibility is Figure 3. The ModelTalk
to maintain the relationships between the DSL and DSLs for use by domain experts (nonprogram- producer-consumer
Java elements. This includes object graph instanti- mers). In ModelTalk, however, developers both layered architecture.
ation and a reflection API.7 When a client requests produce and consume DSLs. Each developer The bottommost layer
a DSL instance, the DSL engine finds the corre- team specializes in a set of domains and shares defines the most
sponding Java class, instantiates it, and injects the its expertise with other teams via DSLs. This cre- generic Meta DSL.
property values into its instance variables. This is ates a supply chain of DSLs in the development DSLs at higher layers
applied recursively for injected values of a complex organization while organizing the DSL artifacts specialize DSLs at
type. The DSL-to-Java mapping allows for DSL in layers. lower layers. The
classes without a Java counterpart. In such cases, All developers are consumers of DSLs residing topmost layer contains
the DSL engine maps the class to its superclass’s at the Core layer. The technical experts are pro- the assembled products
Java counterpart. Consequently, developers and ducers (and the application and customization de- (products A through Z).
even users can change DSL definitions at runtime velopers are consumers) of DSLs at the Platform
without needing to also change the Java code.8 layer. The application developers are producers
The DSL execution engine eliminates the ab- (and the customization developers and business
straction gap between the rich ModelTalk meta- experts are the consumers) of DSLs at the Busi-
model and the one provided in Java, bringing ex- ness layer. The customization developers are pro-
plicit metaclass9 and other advanced capabilities ducers (and the business experts are consumers)
into Java. of DSLs at the Customization layer.
July/August 2009 I E E E S o f t w a r e 41
The Platform layer defines a rich set of DSL alerts the developer about inconsistency between
building blocks for creating business applications. existing DSL instances and their class definition.
In ModelTalk, Many of the DSLs defined in the Platform layer
Implementing DSLs in ModelTalk
the framework are bridges to third-party technologies, such as the
J2EE standard, the Spring framework, Hibernate, To explain the steps in defining instances, properties,
developer and Apache Axis. Concrete examples of DSLs in classes, methods, and metaclasses in ModelTalk,
uses DSLs this layer include Persistency and Data-model. Persistency
wraps the Hibernate framework with a DSL for
we’ll use a simplified example of an online market-
ing system that business experts use to launch tar-
to declaratively handling persistency concerns (for example, que- geted promotions on specific goods.
expose ries and object/relational mapping). The Data-model
DSL uses the Persistency DSL to define business enti- Instances
variability ties. Wrapping a third-party framework in a DSL Figure 4a shows a DSL instance named IEEE_HH.
points in hides in effect the technological complexity from This instance “is kind of” Promotion (in the Smalltalk
imperative the application developers, enabling them to focus
on their domain’s business logic.
sense)—specifically, a member of HappyHour (see the
listing in Figure 4b). It defines a happy-hour dis-
code. The Business layer is a collection of generic, count on subscriptions to IEEE Software targeted
reusable DSLs and constitutes the business logic. at students: $20 off during October 2009. While
Example DSLs residing here for an online mar- specifying this promotion, the DSL programmer
keting system include Goods, Promotion, and Eligibil- is constrained by the type HappyHour. All properties
ity. Goods defines the products and services offered must be assigned a value—that is, who is eligible for
to the customer. Eligibility defines the notion of cus- the promotion (Figure 4a, lines 2−6), the campaign
tomer segments and a set of operators that can time frame (lines 7−10), the incentive given to buy-
be applied to them. Promotion specializes Data-model ers (lines 11−14), and the goods participating in the
and uses Goods and Eligibility. It defines the notion promotion (line 15).
of a product being on sale—that is, the incentive
offered, the targeted segment, and the specific Properties
goods. When editing a DSL instance, you may assign val-
At the top resides the Customization layer, ues only to properties that are defined in the DSL
in which the complete customized systems (final class. The assigned value must be of a type that
products) are assembled mainly from Business- matches the constraints defined in the DSL class.
layer DSLs. DSLs from the Platform layer are also For properties of a complex (user-defined) type, you
used occasionally to customize deep aspects of the must specify an explicit type attribute. In the reward
system. The Customization layer is managed sep- property (Figure 4a, line 11), any subclass of Benefit-
arately for each customer or group of customers, Giver can serve as the type. For example, the menu
and customer-specific features are developed here. in Figure 5e lists FixedAmountDiscount, FixedPercentage-
In the example, Subscription and HappyHour special- Discount, and SubscriptionPeriodExtension as subclasses of
ize Goods and Promotion, respectively, to the IEEE’s BenefitGiver.
specific needs. Choosing the type of a complex property is
significant. At the semantic level, the type deter-
Variability Management and Evolution mines the system behavior. At the mechanical
ModelTalk accommodates the evolution of DSLs. level, the type determines the inner properties that
A new DSL is initially implemented in the Custom- the user should fill in. Setting FixedP ercentageDiscount
ization layer as a one-off customer-specific effort. as the type of benefit instead of FixedAmountD iscount
At that stage, the need for variability is limited, (Figure 4a, line 11) would require the user to
so the DSL exposes only a few variability points. specify the discount percentage instead of the
Gradually, as new requirements accumulate, the amount and currency. The ModelTalk IDE au-
DSL developer identifies and implements new vari- tocompletion feature relieves the programmer
ability points. When the DSL developer recognizes from memorizing the valid choices. This compo-
a potential for significant reuse, additional develop- sition process is recursive, supporting the defini-
ment effort is put into pushing the DSL upstream tion of nested instance graphs. To promote reuse,
in the supply chain—that is, moving the DSL to a ModelTalk also supports references to external
lower layer. The DSL evolves from being a particu- instances as an alternative to inline definitions;
lar asset to being a shared asset. see, for example, the reference to IEEE_Software_
A variability point in ModelTalk is essentially Subscription (denoted by the suffix Ref—that is, by
a DSL class property. When DSLs evolve, the IDE business:SubscriptionRef in Figure 4a, line 15).
Metaclasses
The HappyHour listing in Figure 4b is an instance of Evaluation and Discussion
a specialized metaclass for persistent classes, called Since ModelTalk’s inception, we’ve been collect-
EntityClass (see Figure 4c). HappyHour specifies the per- ing data (duration of edit-execute cycles, compila-
sistency trait using the Persistency DSL (Figure 4b, tion times, error logs, and other code metrics) to as-
lines 2–8). The same rules that apply to instance sess its effectiveness. Figure 7 presents the growth
composition also apply to classes (and metaclasses). over time of the code base (net user-written code,
July/August 2009 I E E E S o f t w a r e 43
Figure 5. The ModelTalk development environment. A set of Eclipse plug-ins offers Java-like programming tool support
for DSL authoring: (a) Eclipse standard navigator view; (b) ModelTalk instance-of hierarchy view; (c) ModelTalk
source code editor; (d) ModelTalk documentation tool tip; (e) ModelTalk autocompletion menu; (f) Eclipse problems
view; (g) ModelTalk toolbar.
01 public class HappyHour extends Promotion { 01 public class TimeWindow extends ScheduleDef {
02 public boolean isEligible() { 02 public boolean isInTimeFrame() {
03 boolean result = super.isEligible(); 03 boolean result = false;
04 if (result) 04 Calendar currentTime=Calendar.getInstance();
05 result=getDateOfPurchase().isInTimeFrame(); 05 if (currentTime.after(getFromTime()))
06 return result; 06 result=currentTime.before(getToTime());
07 } 07 return result;
08 } 08 }
(a) 09 }
(b)
Size (KLOC)
Users have done most of the customization (83 per-
cent of Customization LOC) declaratively, further 100
indicating that the ModelTalk approach scales well.
Organization Perspective 50
An organization considering adopting an approach
similar to ModelTalk should take into account a
(a)
substantial initial investment in building the infra- 0
structure and tools. In ModelTalk, the initial in-
vestment was more than 10 person-years. There’s 100
DSL Business
also an ongoing cost for maintaining the develop-
Size (KLOC)
Java (managed)
ment environment. Java (unmanaged)
From the human-resources and skills-set per- 50
spective, metaprogramming tends to be highly
abstract and generic, so it requires highly capable
individuals who might also need an adjustment pe- (b) 0
riod before becoming productive. We also learned 100
DSL Platform
over time that our approach is less effective in do-
Java (managed)
Size (KLOC)
mains for which rich graphical tools are mature, Java (unmanaged)
such as user interface design and online analytical 50
processing.
Nevertheless, once a development approach
such as ModelTalk is in place, the benefits for the (c) 0
organization are tangible. Specifically, the time-to-
100
market and the cost of producing individual, cus- DSL Core
tomized products drop significantly. In a particular Java (managed)
Size (KLOC)
D
ModelTalk and specifically praise the short edit- Figure 7. The amount
execute cycle. Our data corroborate this: the av- omain-specific languages aim to im- of different kinds of
erage incremental build time is less than 10 sec- prove the development process by rais- code in each layer:
onds per build. Customization developers enjoy ing the level of abstraction around a (a) Customization,
especially short build times because changes in specific area of the problem. Typically, develop- (b) Business,
the top layer have less impact on the system. To ers introduce and apply DSLs on a per-case ba- (c) Platform, (d) Core.
maintain these short build times, we periodically sis only after identifying a specific component The gold lines represent
devote development resources to improving the or concern that might benefit from having a DSL code, the gray lines
DSL processors. Developers appreciate the fact DSL around it. In large systems, this approach represent managed Java
that DSL scripting and Java programming take might result in a number of ad hoc, discon- (Java code governed
place in a unified, integrated environment and nected DSLs. Our work here shows the ben- by ModelTalk), and the
that they can work on incomplete or inconsistent efit in embracing DSLs not only for a small blue lines represent
models. Developers express some dissatisfaction number of components or concerns but also as unmanaged Java code.
with the lack of diagramming capabilities or in- building blocks for systematically constructing
teroperability with UML modeling tools. large software systems.
July/August 2009 I E E E S o f t w a r e 45
Day 89 Day 121
Integration Project
tests start goes live 72%
10 Day 46
Day 21 Ready for integration
8 First major 26%
Size (KLOC)
(a) (b)
Figure 8. A case study of a customization project from kickoff to deployment: (a) the growth of customization code;
(b) breakdown into kinds of code. Once an approach such as ModelTalk is in place, the organizational benefit is clear:
a short time to market.