The Umple Model-Oriented Programming Technology: Easy-to-Use Open-Source Code Generation
description
Transcript of The Umple Model-Oriented Programming Technology: Easy-to-Use Open-Source Code Generation
The UmpleModel-Oriented Programming Technology:
Easy-to-Use Open-Source Code Generation
Code Generation 2013, Cambridge UK
Timothy C. Lethbridge, University of [email protected]
http://www.eecs.uottawa.ca/~tclhttp://www.umple.org
My backgroundOnce worked at Northern Telecom
Collaborated with originators of ObjecTime / IBM Rational Tools since early 1990’s
Professor of software engineering at University of Ottawa• Have taught software engineering since 1991• Research focuses
—Usability of software engineering tools—Empirical studies
Recent research support: IBM, Ericsson, General Motors, Defense Deptartment
T. Lethbridge Code Generation 2013 - Umple 2
MotivationFrom our studies of practitioners
• Code generation is weak in widely-deployed tools• Tools are awkward, do not interoperate• Modellers mostly
—do it for documentation—make important errors
From our teaching of modeling• Students learned syntax, but failed to learn
—Semantics—Pragmatics—To create implementable models due to lack of feedback
T. Lethbridge Code Generation 2013 - Umple 3
Umple: Simple, Ample,UML Programming Language
1. Open source code generator for UML• The only one that has
—Infinitely nested state machines, with concurrency—Proper referential integrity and multiplicity constraints
on associations2. Textual modelling tool set
• Command line compiler• Web-based tool (UmpleOnline) for demos and education• Eclipse plugin
3. Pre-processor to add UML, patterns and other features on top of Java, PhP and other languages
T. Lethbridge Code Generation 2013 - Umple 4
Exercise: Compiling and Changing a Model
Go to http://helloworld.umple.org
Look at the example at the bottom• Observe: attribute, association, class hierarchy, mixin
Click on Load the above code into UmpleOnline• Observe and modify the diagram• Add an attribute• Make a multiplicity error, then undo• Generate code and take a look• Download, compile and run if you want
T. Lethbridge Code Generation 2013 - Umple 5
Demo of the command line Umple compiler
Follows conventions of gcc
Used by ant scripts for building
T. Lethbridge Code Generation 2013 - Umple 6
Umple Philosophy 1-4
P1. Modeling is programming and vice versa
P2. An Umple programmer should never need to edit generated code to accomplish any task.
P3. The Umple compiler can accept and generate code that uses nothing but UML abstractions.
- The above is the inverse of the following
P4. A program without Umple features can be compiled by an Umple compiler.
• e.g. input Java results in the same as output
T. Lethbridge Code Generation 2013 - Umple 7
Umple Philosophy 5-8
P5. A programmer can incrementally add Umple features to an existing program
• Umplification
P6. Umple extends the base language in a minimally invasive and safe way.
P7. Umple features can be created and viewed diagrammatically or textually
P8. Umple goes beyond UML
T. Lethbridge Code Generation 2013 - Umple 8
A look at selected Umple features
Attributes• http://attributes.umple.org
Associations• http://associations.umple.org• Notice the inline and independent state machines
State Machines• http://statemachines.umple.org• Switch to ‘GraphViz state diagram’ in the options menu
T. Lethbridge Code Generation 2013 - Umple 9
Umple Architecture 1
Grammar DSL: Online• http://grammar.umple.org• (we migrated from Antlr to better handle embedded code
blocks and gain flexibility)
Umple is written in itself• Key to testing and reliability• http://code.google.com/p/umple/source/browse/trunk/cru
ise.umple/src/Umple.ump
T. Lethbridge Code Generation 2013 - Umple 10
Umple Architecture 2
Umple’s own class diagram generated by itself from itself:
• http://metamodel.umple.org• Colours represent key subsystems• Click on classes to see Javadoc, and then Umple Code
T. Lethbridge Code Generation 2013 - Umple 11
Testing:TDD with100% pass always required
Multiple levels: • Parsing tests: basic constructs• Metamodel tests: ensure it is populated properly
—E.g. http://code.google.com/p/umple/source/browse/trunk/cruise.umple/test/cruise/umple/compiler/AssociationTest.java
• Implementation template tests: to ensure constructs generate code that looks as expected
• Testbed semantic tests: Generate code and make sure it behaves the way it should
T. Lethbridge Code Generation 2013 - Umple 12
Continuous integrationSmall increments compiled frequently
http://cc.umple.org • Single trunk, no branches for now
Online QA report: http://qa.umple.org
T. Lethbridge Code Generation 2013 - Umple 13
Code Generation Approach 1
Generation relies on ‘walking’ the metamodel
Where possible, new features are added by layering on top of the existing ones
• e.g. —There was an existing ‘code injection’ feature—Constraints were implemented almost entirely at the
metamodel level by adding ‘before’ and ‘after’ code injections
T. Lethbridge Code Generation 2013 - Umple 14
Code Generation Approach 2Each generator is a separate plugin and can have a different
architecture
Use Jet templates• Language independent common templates
—http://code.google.com/p/umple/source/browse/#svn%2Ftrunk%2FUmpleToTemplate%2Ftemplates
• Language-specific templates —http://code.google.com/p/umple/source/browse/#svn%2Ftrunk%2F
UmpleToJava%2Ftemplates
• Language-specific translation functions—http://code.google.com/p/umple/source/browse/trunk/
cruise.umple/src/Generator_CodeJava.ump
T. Lethbridge Code Generation 2013 - Umple 15
Code generation lessons from Umple 1Process of developing Umple
• Agile continuous integration• Language written in itself• Multi-level test-driven development
Process for all users of Umple• Modeling and programming at the same level• Many semantic model checks produce warnings & errors• Round trip engineering is banished• Generation of diagrams from text and text from diagrams• IDE Flexibility: Eclipse / Web / Command line• Incremental umplification
T. Lethbridge Code Generation 2013 - Umple 16
Code generation lessons from Umple 2Language features
• Deep attention to detail in state machines and UML associations
• Mixins for separation of concerns• Multi-lingual generation and embedding• Generated code looks nice
—No ‘Umple runtime’—Can be inspected to gain confidence—No risk adoption
T. Lethbridge Code Generation 2013 - Umple 17
Evidence of benefit
Umple in use an a couple of small companies
Umple development in itself• 20+ developers
Empirical studies show• Umple code is easier to understand than Java• Helps students learn to model: CSEE&T
T. Lethbridge Code Generation 2013 - Umple 18
Results of survey
T. Lethbridge CSEE&T 2011 19
Umpl
e in t
he cl
assr
oom
help
ed m
e und
ersta
nd co
ncep
ts
Umpl
e in t
he la
b he
lped
me u
nder
stand
conc
epts
I will
get b
etter
grad
esbe
caus
e of U
mpl
e
Prof
. Leth
brid
ge sh
ould
use i
t in
futu
re co
urse
s
As of D
ec 20
10, U
mpl
e is
too i
ncom
plete
or b
uggy
Other
tools
wou
ld
have
been
just
as
effec
tive
I wou
ld u
se U
mpl
e in
the
futu
re, a
ssum
ing b
ugs f
ixed
T. Lethbridge CSEE&T 2011 20
Availa
bilit
y of a
text
ual f
orm
for m
odels
and d
iagra
ms
Abilit
y to e
dit d
iagra
m or
text
& ha
ve th
e oth
er re
flect
chan
ges
Abilit
y to g
ener
ate c
ode t
o
repr
esen
t the
mod
el
Comparison of GradesComparison of 4 offerings of the same course before
introducing Umple, and 2 offerings afterwards
Midterm examination grades on UML modeling question rose from 75.8% to 82.3%
• 8.6% improvement
Final exam grades on UML modeling questions rose from 76.4% to 83.6%
• 9.4% improvement
Highly statistically significant p<0.00002 on T Test• n=332 prior to Umple; n=137 afterwards
Similar results in 4th year course SEG4110No difference in non-UML questions
T. Lethbridge CSEE&T 2011 21
The Near Future
Real time UML/Autosar extensions
Robust C/C++ generation
Application for Eclipse Foundation hosting
Seek industrial uptake
T. Lethbridge Code Generation 2013 - Umple 22
A Few Direct Web LinksUmpleOnlinehttp://try.umple.org
User Manualhttp://manual.umple.org
Google Code Hosting Sitehttp://code.umple.org
This presentation:http://www.site.uottawa.ca/~tcl/presentations/
UmpleTutorial-CodeGeneration.ppt
T. Lethbridge Code Generation 2013 - Umple 23
Questions?
T. Lethbridge Code Generation 2013 - Umple 24