workshop at cargil eld perdita stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfother examples lines...

41
Bidirectional transformations workshop at Cargilfield Perdita Stevens University of Edinburgh June 2017

Upload: others

Post on 07-Sep-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Bidirectional transformations

workshop at Cargilfield

Perdita Stevens

University of Edinburgh

June 2017

Page 2: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Who am I? What’s my job?

Perdita Stevens

(Robin Bradfield’s mother!)

Professor of Mathematics of Software Engineering

University of Edinburgh

Page 3: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

What’s software?

opposite of hardware

all the computery stuff you can’t break with a hammer...

Have you written a Scratch program?

Like that but bigger...

Page 4: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

What’s software?

opposite of hardware

all the computery stuff you can’t break with a hammer...

Have you written a Scratch program?

Like that but bigger...

Page 5: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

What’s software?

opposite of hardware

all the computery stuff you can’t break with a hammer...

Have you written a Scratch program?

Like that but bigger...

Page 6: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Almost random example bit of code

void SAL_CALL BaseContainerControl::dispose() throw( RuntimeException,

std::exception )

{

// Tell everything that this container is now gone.

// It’s faster if you listen to both the control and the container.

// Ready for multithreading

MutexGuard aGuard( m_aMutex );

// remove listeners

EventObject aObject;

aObject.Source.set( static_cast<XControlContainer*>(this), UNO_QUERY );

m_aListeners.disposeAndClear( aObject );

// remove controls

Sequence< Reference< XControl > > seqCtrls = getControls();

Reference< XControl > * pCtrls =

seqCtrls.getArray();

sal_uInt32 nCtrls =

seqCtrls.getLength();

size_t nMaxCount =

maControlInfoList.size();

size_t nCount = 0;

for ( nCount = 0; nCount < nMaxCount; ++nCount )

{

delete maControlInfoList[ nCount ];

}

maControlInfoList.clear();

for ( nCount = 0; nCount < nCtrls; ++nCount )

{

pCtrls [ nCount ] -> removeEventListener ( static_cast<

XEventListener* >( static_cast< XWindowListener* >( this ) ) );

pCtrls [ nCount ] -> dispose ( );

}

// call baseclass

BaseControl::dispose();

}

Page 7: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about
Page 8: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Size...“In a Nutshell, LibreOffice...

...

has had 452,587 commits made by 1,672 contributors representing9,087,155 lines of code

...

is mostly written in C++ with an average number of source codecomments

...

has a well established, mature codebase maintained by a very largedevelopment team with stable Y-O-Y commits

...

took an estimated 2,773 years of effort (COCOMO model) startingwith its first commit in September, 2000 ending with its mostrecent commit 18 days ago ”https://www.openhub.net/p/libreoffice as at 19/6/17

Page 9: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Other examples

Lines of code in:

A simple game on a mobile phone: about 10,000

A heart pacemaker: about 80,000

The Hubble Space Telescope: about 2,000,000

Curiosity Mars Rover: about 2,500,000 (or is it about5,000,000? Does it matter?)

A Boeing 787: about 14,000,000

Average modern high-end car: about 100,000,000

All Google’s code, in 2015: about 2,000,000,000

Sources: http://www.visualcapitalist.com/millions-lines-of-code/

http://www.itworld.com/article/2985099/application-management/

thats-one-big-repository-heres-how-many-lines-of-code-google-has.html

Page 10: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Other examples

Lines of code in:

A simple game on a mobile phone: about 10,000

A heart pacemaker: about 80,000

The Hubble Space Telescope: about 2,000,000

Curiosity Mars Rover: about 2,500,000 (or is it about5,000,000? Does it matter?)

A Boeing 787: about 14,000,000

Average modern high-end car: about 100,000,000

All Google’s code, in 2015: about 2,000,000,000

Sources: http://www.visualcapitalist.com/millions-lines-of-code/

http://www.itworld.com/article/2985099/application-management/

thats-one-big-repository-heres-how-many-lines-of-code-google-has.html

Page 11: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Other examples

Lines of code in:

A simple game on a mobile phone: about 10,000

A heart pacemaker: about 80,000

The Hubble Space Telescope: about 2,000,000

Curiosity Mars Rover: about 2,500,000 (or is it about5,000,000? Does it matter?)

A Boeing 787: about 14,000,000

Average modern high-end car: about 100,000,000

All Google’s code, in 2015: about 2,000,000,000

Sources: http://www.visualcapitalist.com/millions-lines-of-code/

http://www.itworld.com/article/2985099/application-management/

thats-one-big-repository-heres-how-many-lines-of-code-google-has.html

Page 12: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Other examples

Lines of code in:

A simple game on a mobile phone: about 10,000

A heart pacemaker: about 80,000

The Hubble Space Telescope: about 2,000,000

Curiosity Mars Rover: about 2,500,000 (or is it about5,000,000? Does it matter?)

A Boeing 787: about 14,000,000

Average modern high-end car: about 100,000,000

All Google’s code, in 2015: about 2,000,000,000

Sources: http://www.visualcapitalist.com/millions-lines-of-code/

http://www.itworld.com/article/2985099/application-management/

thats-one-big-repository-heres-how-many-lines-of-code-google-has.html

Page 13: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Other examples

Lines of code in:

A simple game on a mobile phone: about 10,000

A heart pacemaker: about 80,000

The Hubble Space Telescope: about 2,000,000

Curiosity Mars Rover: about 2,500,000 (or is it about5,000,000? Does it matter?)

A Boeing 787: about 14,000,000

Average modern high-end car: about 100,000,000

All Google’s code, in 2015: about 2,000,000,000

Sources: http://www.visualcapitalist.com/millions-lines-of-code/

http://www.itworld.com/article/2985099/application-management/

thats-one-big-repository-heres-how-many-lines-of-code-google-has.html

Page 14: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Other examples

Lines of code in:

A simple game on a mobile phone: about 10,000

A heart pacemaker: about 80,000

The Hubble Space Telescope: about 2,000,000

Curiosity Mars Rover: about 2,500,000 (or is it about5,000,000? Does it matter?)

A Boeing 787: about 14,000,000

Average modern high-end car: about 100,000,000

All Google’s code, in 2015: about 2,000,000,000

Sources: http://www.visualcapitalist.com/millions-lines-of-code/

http://www.itworld.com/article/2985099/application-management/

thats-one-big-repository-heres-how-many-lines-of-code-google-has.html

Page 15: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Other examples

Lines of code in:

A simple game on a mobile phone: about 10,000

A heart pacemaker: about 80,000

The Hubble Space Telescope: about 2,000,000

Curiosity Mars Rover: about 2,500,000 (or is it about5,000,000? Does it matter?)

A Boeing 787: about 14,000,000

Average modern high-end car: about 100,000,000

All Google’s code, in 2015: about 2,000,000,000

Sources: http://www.visualcapitalist.com/millions-lines-of-code/

http://www.itworld.com/article/2985099/application-management/

thats-one-big-repository-heres-how-many-lines-of-code-google-has.html

Page 16: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Other examples

Lines of code in:

A simple game on a mobile phone: about 10,000

A heart pacemaker: about 80,000

The Hubble Space Telescope: about 2,000,000

Curiosity Mars Rover: about 2,500,000 (or is it about5,000,000? Does it matter?)

A Boeing 787: about 14,000,000

Average modern high-end car: about 100,000,000

All Google’s code, in 2015: about 2,000,000,000

Sources: http://www.visualcapitalist.com/millions-lines-of-code/

http://www.itworld.com/article/2985099/application-management/

thats-one-big-repository-heres-how-many-lines-of-code-google-has.html

Page 17: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Other examples

Lines of code in:

A simple game on a mobile phone: about 10,000

A heart pacemaker: about 80,000

The Hubble Space Telescope: about 2,000,000

Curiosity Mars Rover: about 2,500,000 (or is it about5,000,000? Does it matter?)

A Boeing 787: about 14,000,000

Average modern high-end car: about 100,000,000

All Google’s code, in 2015: about 2,000,000,000

Sources: http://www.visualcapitalist.com/millions-lines-of-code/

http://www.itworld.com/article/2985099/application-management/

thats-one-big-repository-heres-how-many-lines-of-code-google-has.html

Page 18: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Problem

Software is too big and toocomplicated!

How do people cope?

Page 19: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Abstraction

Minecraft world built by Robin Bradfield

Page 20: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Abstraction

Minecraft world built by Robin Bradfield

Page 21: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Abstraction

Page 22: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Abstraction

is when you get rid of details that aren’t important right now

to focus on the things that are.

Page 23: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Abstraction in maths

+ =

1 shoe + 1 shoe = 2 shoes

1 + 1 = 2

Page 24: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Abstraction in maths

+ =

1 shoe + 1 shoe = 2 shoes

1 + 1 = 2

Page 25: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Abstraction in maths

+ =

1 shoe + 1 shoe = 2 shoes

1 + 1 = 2

Page 26: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Abstraction in software engineering

From punched cards:

Page 27: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

to “high level code” like we saw beforevoid SAL_CALL BaseContainerControl::dispose() throw( RuntimeException,

std::exception )

{

// Tell everything that this container is now gone.

// It’s faster if you listen to both the control and the container.

// Ready for multithreading

MutexGuard aGuard( m_aMutex );

// remove listeners

EventObject aObject;

aObject.Source.set( static_cast<XControlContainer*>(this), UNO_QUERY );

m_aListeners.disposeAndClear( aObject );

// remove controls

Sequence< Reference< XControl > > seqCtrls = getControls();

Reference< XControl > * pCtrls =

seqCtrls.getArray();

sal_uInt32 nCtrls =

seqCtrls.getLength();

size_t nMaxCount =

maControlInfoList.size();

size_t nCount = 0;

for ( nCount = 0; nCount < nMaxCount; ++nCount )

{

delete maControlInfoList[ nCount ];

}

maControlInfoList.clear();

for ( nCount = 0; nCount < nCtrls; ++nCount )

{

pCtrls [ nCount ] -> removeEventListener ( static_cast<

XEventListener* >( static_cast< XWindowListener* >( this ) ) );

pCtrls [ nCount ] -> dispose ( );

}

// call baseclass

BaseControl::dispose();

}

Page 28: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

to models, e.g. like this

By Kishorekumar 62 - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=5766927

https://en.wikipedia.org/wiki/Unified_Modeling_Language

Page 29: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Model-driven development

Page 30: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Consistency

In the end two models have to be consistent, if they are both to beabstractions of the same software system.

What consistent means is very variable...

Now you’ll do an exercise in pairs about consistency.

Page 31: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Discussion

What can vary? How is it decided?

If you have a definition of consistency, and one model, canyou tell what the other model must be?

Page 32: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Discussion

What can vary? How is it decided?

If you have a definition of consistency, and one model, canyou tell what the other model must be?

Page 33: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

UML class diagram

Robot

Head

smile()speak()

MovementPlanner

acquireObject()

Leg

jump()getHeightRequired()

Arm

wave()

Page 34: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

UML sequence diagram:Robot :MovementPlanner :Leg

acquireObject()

jump()

getHeightRequired()

Page 35: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

What if two models are not consistent?

This time your task is to make the models consistent, according tothe definition on the sheet, by changing the second model ifnecessary.

Discuss:

Is there a choice, or just one way to do it?

If there’s a choice, which way to restore consistency is best?

Why? How can we decide?

(Stretch) Can you explain how to restore this notion ofconsistency for any pair of models?

Page 36: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Writing bidirectional transformations

Deciding

what kind of consistency we need

how we can restore consistency automatically

is what the writer of a bidirectional transformation (bx) has to do.

We don’t yet have good languages in which to write bx – that’songoing research.

Page 37: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

More ongoing research

What properties should bidirectional transformations have?

correctness: they actually should restore consistency!

hippocraticness: if the models are already consistent, restoringconsistency does nothing

least change: ???

Page 38: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

More ongoing research

What properties should bidirectional transformations have?

correctness: they actually should restore consistency!

hippocraticness: if the models are already consistent, restoringconsistency does nothing

least change: ???

Page 39: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

More ongoing research

What properties should bidirectional transformations have?

correctness: they actually should restore consistency!

hippocraticness: if the models are already consistent, restoringconsistency does nothing

least change: ???

Page 40: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

About software engineering as a job

Today, programming is a big part of software engineering...

... but other parts are just as important, e.g., requirementsengineering.

Will change a lot in your working lives!

Work hard at your maths :-)

Page 41: workshop at Cargil eld Perdita Stevenshomepages.inf.ed.ac.uk/perdita/slides.pdfOther examples Lines of code in: A simple game on a mobile phone: about 10,000 A heart pacemaker: about

Questions?

Comments?