+ All Categories
Home > Technology > Overcoming The Impedance Mismatch Between Source Code And Architecture

Overcoming The Impedance Mismatch Between Source Code And Architecture

Date post: 15-Jan-2015
Category:
Upload: peter-friese
View: 4,243 times
Download: 1 times
Share this document with a friend
Description:
In this talk, I show why UML sucks and why developers should move away from writing *boring* code to writing *exciting* code!
Popular Tags:
92
Overcoming the Impedance Mismatch Between Source Code and Architecture Peter Friese, itemis @peterfriese @xtext (c) 2009 Peter Friese. Distributed under the EDL V1.0 - http://www.eclipse.org/org/documents/edl-v10.php More info: http://www.peterfriese.de / http://www.itemis.com
Transcript
Page 1: Overcoming The Impedance Mismatch Between Source Code And Architecture

Overcoming the Impedance Mismatch

Between Source Code and Architecture

Peter Friese, itemis

@peterfriese@xtext

(c) 2009 Peter Friese. Distributed under the EDL V1.0 - http://www.eclipse.org/org/documents/edl-v10.phpMore info: http://www.peterfriese.de / http://www.itemis.com

Page 2: Overcoming The Impedance Mismatch Between Source Code And Architecture

Stop drawing useless diagrams

and writing boring codePeter Friese, itemis

@peterfriese@xtext

(c) 2009 Peter Friese. Distributed under the EDL V1.0 - http://www.eclipse.org/org/documents/edl-v10.phpMore info: http://www.peterfriese.de / http://www.itemis.com

Page 3: Overcoming The Impedance Mismatch Between Source Code And Architecture

UML - One Language To Rule Them All

http://en.wikipedia.org/wiki/File:UML_Diagrams.jpg

Page 4: Overcoming The Impedance Mismatch Between Source Code And Architecture

UML doesn’t cut it!

Page 5: Overcoming The Impedance Mismatch Between Source Code And Architecture
Page 6: Overcoming The Impedance Mismatch Between Source Code And Architecture

Increasing Gap

Page 7: Overcoming The Impedance Mismatch Between Source Code And Architecture

Increasing Gap

Models

Code

Page 8: Overcoming The Impedance Mismatch Between Source Code And Architecture

(UML) Models = Shelfware

http://www.flickr.com/photos/misterdna/49841409/

Page 9: Overcoming The Impedance Mismatch Between Source Code And Architecture

Solution: Two-Way Tools

Page 10: Overcoming The Impedance Mismatch Between Source Code And Architecture

Result: Bloated Diagrams No-one can understand

Librarian

Person

Fee

Administrator

User

Folder

Shelf

Library

Author

Page

Book

SomeOtherMeaninglessClass

SomeOtherMeaninglessClass

SomeOtherMeaninglessClass

SomeOtherMeaninglessClass

SomeOtherMeaninglessClass

SomeOtherMeaninglessClass

SomeOtherMeaninglessClass

SomeOtherMeaninglessClass

Page 11: Overcoming The Impedance Mismatch Between Source Code And Architecture

Solution: Semantic Diagrams

title: Stringisbn: String

<<EntityBean>>Book

Page 12: Overcoming The Impedance Mismatch Between Source Code And Architecture

Instead of being a solution...

Page 13: Overcoming The Impedance Mismatch Between Source Code And Architecture

... two-way tools have proven to be a dead-end

http://www.flickr.com/photos/cgommel/561929101/

Page 14: Overcoming The Impedance Mismatch Between Source Code And Architecture

... two-way tools have proven to be a dead-end

http://www.flickr.com/photos/cgommel/561929101/

Page 15: Overcoming The Impedance Mismatch Between Source Code And Architecture

Let’s step back

Page 16: Overcoming The Impedance Mismatch Between Source Code And Architecture

What are the real problems?

Page 17: Overcoming The Impedance Mismatch Between Source Code And Architecture

Boring code

Page 18: Overcoming The Impedance Mismatch Between Source Code And Architecture

Accidental complexity

Page 19: Overcoming The Impedance Mismatch Between Source Code And Architecture

Wrong level of abstraction

Page 20: Overcoming The Impedance Mismatch Between Source Code And Architecture

Anatomy of Modern Software

Software artifact

Page 21: Overcoming The Impedance Mismatch Between Source Code And Architecture

Anatomy of Modern Software

Libraries

Frameworksmanually written code

Page 22: Overcoming The Impedance Mismatch Between Source Code And Architecture

Anatomy of Modern Software

schematic code (manually written)

Libraries

Frameworks

manually written code

Page 23: Overcoming The Impedance Mismatch Between Source Code And Architecture

(Rote) coding doesn’t cut it either!

Page 24: Overcoming The Impedance Mismatch Between Source Code And Architecture
Page 25: Overcoming The Impedance Mismatch Between Source Code And Architecture

Problems

Page 26: Overcoming The Impedance Mismatch Between Source Code And Architecture

Problems

Can we solve them with models?

Page 27: Overcoming The Impedance Mismatch Between Source Code And Architecture

Yes, we can!

Page 28: Overcoming The Impedance Mismatch Between Source Code And Architecture

schematic code (generated)

Libraries

Frameworks

manually written code

Model

Generator

Code Generation Helps

Page 29: Overcoming The Impedance Mismatch Between Source Code And Architecture

MDSD

Metamodel

Model

<<instanceof>>

Generator

Modelgeneratedcode

Platform

manually written code

Page 30: Overcoming The Impedance Mismatch Between Source Code And Architecture

MDSD with UML

UML

Metamodel

Model

<<instanceof>>

Generator

Modelgeneratedcode

Platform

manually written code

Page 31: Overcoming The Impedance Mismatch Between Source Code And Architecture

UML and MDSD

Page 32: Overcoming The Impedance Mismatch Between Source Code And Architecture

A Marriage Made in Heaven?

Page 33: Overcoming The Impedance Mismatch Between Source Code And Architecture

Not.

Page 34: Overcoming The Impedance Mismatch Between Source Code And Architecture

UML and MDSD

⊕ Existing tools⊕ Good overview⊕ Graphical - managers / clients like that⊖ complex meta model⊖ teamwork challenging at best⊖ model evolution problematic⊖ UML is too generic, it’s not a DSL⊖ UML profiles don’t help either⊖ tools not integrated in IDE⊖ long round trips⊖ developers don’t like diagrams that much

Page 35: Overcoming The Impedance Mismatch Between Source Code And Architecture

UML doesn’t cut it!

Page 36: Overcoming The Impedance Mismatch Between Source Code And Architecture
Page 37: Overcoming The Impedance Mismatch Between Source Code And Architecture

Looking at the drawbacks...

Page 38: Overcoming The Impedance Mismatch Between Source Code And Architecture

⊖ complex meta model⊖ teamwork challenging at best⊖ model evolution problematic⊖ UML is too generic, it’s not a DSL⊖ UML profiles don’t help either⊖ tools not integrated in IDE⊖ long round trips⊖ developers don’t like diagrams that much

UML and MDSD

Page 39: Overcoming The Impedance Mismatch Between Source Code And Architecture

... these are promises of DSLs!

Page 40: Overcoming The Impedance Mismatch Between Source Code And Architecture

What are DSLs?

Page 41: Overcoming The Impedance Mismatch Between Source Code And Architecture

Suppose...

Page 42: Overcoming The Impedance Mismatch Between Source Code And Architecture

You’d want to core an apple...

Page 43: Overcoming The Impedance Mismatch Between Source Code And Architecture

... for your kids.

Page 44: Overcoming The Impedance Mismatch Between Source Code And Architecture

Right tool for the job?

?

Page 45: Overcoming The Impedance Mismatch Between Source Code And Architecture

Your trusty swiss army knife!

Page 46: Overcoming The Impedance Mismatch Between Source Code And Architecture

You can use it for other stuff, too.E.g., opening a bottle of wine.

Page 47: Overcoming The Impedance Mismatch Between Source Code And Architecture

Suppose...

Page 48: Overcoming The Impedance Mismatch Between Source Code And Architecture

You’d want to core a few more apples...

Page 49: Overcoming The Impedance Mismatch Between Source Code And Architecture

... for an apple cake.

Page 50: Overcoming The Impedance Mismatch Between Source Code And Architecture

Still the best tool for the job?

Page 51: Overcoming The Impedance Mismatch Between Source Code And Architecture

Better use this one.

Page 52: Overcoming The Impedance Mismatch Between Source Code And Architecture

and this one:

Page 53: Overcoming The Impedance Mismatch Between Source Code And Architecture

avoid the unitasker!

BUT

Page 54: Overcoming The Impedance Mismatch Between Source Code And Architecture

avoid the unitasker!

BUT

Page 55: Overcoming The Impedance Mismatch Between Source Code And Architecture

A DSL is...

Page 56: Overcoming The Impedance Mismatch Between Source Code And Architecture

A specific toolfor a specific job

Page 57: Overcoming The Impedance Mismatch Between Source Code And Architecture

A specific toolfor a specific job

Page 58: Overcoming The Impedance Mismatch Between Source Code And Architecture

DSL Samples

Page 59: Overcoming The Impedance Mismatch Between Source Code And Architecture

select name, salaryfrom employees where salary > 2000order by salary

Page 60: Overcoming The Impedance Mismatch Between Source Code And Architecture

<project name="MyProject" default="dist" basedir="."> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/>

<target name="init"> <mkdir dir="${build}"/> </target>

<target name="compile" depends="init"> <javac srcdir="${src}" destdir="${build}"/> </target>

<target name="dist" depends="compile"> <mkdir dir="${dist}/lib"/> <jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/> </target>

<target name="clean"> <delete dir="${build}"/> <delete dir="${dist}"/> </target></project>

Page 61: Overcoming The Impedance Mismatch Between Source Code And Architecture

<project name="MyProject" default="dist" basedir="."> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/>

<target name="init"> <mkdir dir="${build}"/> </target>

<target name="compile" depends="init"> <javac srcdir="${src}" destdir="${build}"/> </target>

<target name="dist" depends="compile"> <mkdir dir="${dist}/lib"/> <jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/> </target>

<target name="clean"> <delete dir="${build}"/> <delete dir="${dist}"/> </target></project>

Page 62: Overcoming The Impedance Mismatch Between Source Code And Architecture

DSL Advantages⊕ Focussed⊕ Precise metamodel, perfect fit⊕ No misuse / mismodeling (thanks to constrained meta model)⊕ diff / merge possible⊕ teamwork possible⊕ developers like text⊖ need to build your own tools

Page 63: Overcoming The Impedance Mismatch Between Source Code And Architecture

DSL Disadvantages⊕ Focussed⊕ Precise metamodel, perfect fit⊕ No misuse / mismodeling (thanks to constrained meta model)⊕ diff / merge possible⊕ teamwork possible⊕ developers like text⊖ need to build your own tools

Page 64: Overcoming The Impedance Mismatch Between Source Code And Architecture

1)Create ANTLR grammar2)Generate lexer / parser3)Parser will create parse tree4)Transform parse tree to semantic model

5)Iterate model6)Pass model element(s) to template

Page 65: Overcoming The Impedance Mismatch Between Source Code And Architecture

DSLs are...

Page 66: Overcoming The Impedance Mismatch Between Source Code And Architecture

Flexible

Page 67: Overcoming The Impedance Mismatch Between Source Code And Architecture

Adaptable

Page 68: Overcoming The Impedance Mismatch Between Source Code And Architecture

Complicated

Page 69: Overcoming The Impedance Mismatch Between Source Code And Architecture

Expensive

Page 70: Overcoming The Impedance Mismatch Between Source Code And Architecture

- A DSL for Writing DSLs

Page 71: Overcoming The Impedance Mismatch Between Source Code And Architecture

Underlying Technology

Page 72: Overcoming The Impedance Mismatch Between Source Code And Architecture

Superclass

Subclass Class

ECore meta modelLL(*) Parser Editor

Model

Grammar

Generator

Runtime

Page 73: Overcoming The Impedance Mismatch Between Source Code And Architecture

Grammar (similar to EBNF)grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals

generate entity "http://www.xtext.org/example/Entity"

Model: (types+=Type)*;

Type: TypeDef | Entity; TypeDef: "typedef" name=ID ("mapsto" mappedType=JAVAID)?; JAVAID: name=ID("." ID)*; Entity: "entity" name=ID ("extends" superEntity=[Entity])? "{" (attributes+=Attribute)* "}"; Attribute: type=[Type] (many?="*")? name=ID;

Page 74: Overcoming The Impedance Mismatch Between Source Code And Architecture

grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals

generate entity "http://www.xtext.org/example/Entity"

Model: (types+=Type)*;

Type: TypeDef | Entity; TypeDef: "typedef" name=ID ("mapsto" mappedType=JAVAID)?; JAVAID: name=ID("." ID)*; Entity: "entity" name=ID ("extends" superEntity=[Entity])? "{" (attributes+=Attribute)* "}"; Attribute: type=[Type] (many?="*")? name=ID;

entity

Model

*

name: EStringType

types

TypeDef Entity

name: EStringJAVAID

superEntity

mappedType

name: EStringmany: EBoolean

Attribute

attributes

type

Meta model inference

Page 75: Overcoming The Impedance Mismatch Between Source Code And Architecture

grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals

generate entity "http://www.xtext.org/example/Entity"

Model: (types+=Type)*;

Type: TypeDef | Entity; TypeDef: "typedef" name=ID ("mapsto" mappedType=JAVAID)?; JAVAID: name=ID("." ID)*; Entity: "entity" name=ID ("extends" superEntity=[Entity])? "{" (attributes+=Attribute)* "}"; Attribute: type=[Type] (many?="*")? name=ID;

entity

Model

*

name: EStringType

types

TypeDef Entity

name: EStringJAVAID

superEntity

mappedType

name: EStringmany: EBoolean

Attribute

attributes

type

Meta model inference

Rules -> Classes

Page 76: Overcoming The Impedance Mismatch Between Source Code And Architecture

grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals

generate entity "http://www.xtext.org/example/Entity"

Model: (types+=Type)*;

Type: TypeDef | Entity; TypeDef: "typedef" name=ID ("mapsto" mappedType=JAVAID)?; JAVAID: name=ID("." ID)*; Entity: "entity" name=ID ("extends" superEntity=[Entity])? "{" (attributes+=Attribute)* "}"; Attribute: type=[Type] (many?="*")? name=ID;

entity

Model

*

name: EStringType

types

TypeDef Entity

name: EStringJAVAID

superEntity

mappedType

name: EStringmany: EBoolean

Attribute

attributes

type

Meta model inference

Alternatives -> Hierarchy

Page 77: Overcoming The Impedance Mismatch Between Source Code And Architecture

grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals

generate entity "http://www.xtext.org/example/Entity"

Model: (types+=Type)*;

Type: TypeDef | Entity; TypeDef: "typedef" name=ID ("mapsto" mappedType=JAVAID)?; JAVAID: name=ID("." ID)*; Entity: "entity" name=ID ("extends" superEntity=[Entity])? "{" (attributes+=Attribute)* "}"; Attribute: type=[Type] (many?="*")? name=ID;

entity

Model

*

name: EStringType

types

TypeDef Entity

name: EStringJAVAID

superEntity

mappedType

name: EStringmany: EBoolean

Attribute

attributes

type

Meta model inference

Assignment -> Feature

Page 78: Overcoming The Impedance Mismatch Between Source Code And Architecture

Demo

Page 79: Overcoming The Impedance Mismatch Between Source Code And Architecture
Page 80: Overcoming The Impedance Mismatch Between Source Code And Architecture

Do DSLs cut it?

Page 81: Overcoming The Impedance Mismatch Between Source Code And Architecture
Page 82: Overcoming The Impedance Mismatch Between Source Code And Architecture

Yes, they do

Page 83: Overcoming The Impedance Mismatch Between Source Code And Architecture

Yes, they do

Page 84: Overcoming The Impedance Mismatch Between Source Code And Architecture

Yes, they do

Page 85: Overcoming The Impedance Mismatch Between Source Code And Architecture

Yes, they do

Page 86: Overcoming The Impedance Mismatch Between Source Code And Architecture

Concentrate on Essentials

Page 87: Overcoming The Impedance Mismatch Between Source Code And Architecture

Higher Efficiency

Page 88: Overcoming The Impedance Mismatch Between Source Code And Architecture

Better Maintainability

Page 89: Overcoming The Impedance Mismatch Between Source Code And Architecture

No More Boring Code

Page 90: Overcoming The Impedance Mismatch Between Source Code And Architecture

A New Babylonic Plethora of Languages?

Page 91: Overcoming The Impedance Mismatch Between Source Code And Architecture

DSLs will improve communication in projects

Page 92: Overcoming The Impedance Mismatch Between Source Code And Architecture

Four Things To Take Home

Beware of the shelfware trap

Stop writing boring code

Choose appropriate abstractions

Better understand your stakeholders


Recommended