Model-Minded Development George Fairbanks GOTO Berlin 10 November - - PowerPoint PPT Presentation

model minded development
SMART_READER_LITE
LIVE PREVIEW

Model-Minded Development George Fairbanks GOTO Berlin 10 November - - PowerPoint PPT Presentation

Model-Minded Development George Fairbanks GOTO Berlin 10 November 2016 1 How does your team build software? 2 How does your team build software? Simple process 1. Get new requirement 2. Write test case 3. Edit code minimally so test


slide-1
SLIDE 1

Model-Minded Development

George Fairbanks GOTO Berlin 10 November 2016

1

slide-2
SLIDE 2

How does your team build software?

2

slide-3
SLIDE 3

How does your team build software?

Simple process 1. Get new requirement 2. Write test case 3. Edit code minimally so test passes 4. Refactor to remove code duplication

3

slide-4
SLIDE 4

How does your team build software?

Simple process 1. Get new requirement 2. Write test case 3. Edit code minimally so test passes 4. Refactor to remove code duplication

No models!?

4

slide-5
SLIDE 5

Developers weave models

Developers keep in mind many abstract yet complex models that constrain the code they write

  • Domain driven design
  • Design patterns
  • Architectural styles
  • Test Driven Design (TDD)
  • Programming styles (functional, OO, procedural, etc.)
  • ...

5

slide-6
SLIDE 6

What is Model-Minded Development?

It’s the general idea behind many specific ones: Modeling should be a first-class activity in software development

6

slide-7
SLIDE 7

Example behavior with/without models

Without models 1. Get new requirement 2. Write test case 3. Edit code minimally so test passes 4. Refactor to remove code duplication With models 1. Get new requirement 2. Does it challenge our models? a. E.g., client-server still OK? b. E.g., domain model still OK? 3. Revise models 4. Write test case 5. Revise code to match model

7

slide-8
SLIDE 8

This talk

Main sections:

  • 1. Programming is theory building
  • 2. Programming is distributed cognition
  • 3. What are our software theories / models?

8

slide-9
SLIDE 9

Programming is theory building

9

slide-10
SLIDE 10

Peter Naur (1985) Programming as Theory Building [P]rogramming properly should be regarded as an activity by which the programmers form or achieve a certain kind of insight, a theory, of the matters at hand. This suggestion is in contrast to what appears to be a more common notion, that programming should be regarded as a production of a program and certain

  • ther texts.

Emphasis added

10

slide-11
SLIDE 11

Understanding addition

Knowing that Memorized facts

  • Know that 3+4=7
  • Memorize addition table
  • No answers after, eg, 6+6

No understanding; no theory

Gilbert Ryle (1949): Knowing How and Knowing That

11

slide-12
SLIDE 12

Understanding addition

Knowing that Memorized facts

  • Know that 3+4=7
  • Memorize addition table
  • No answers after, eg, 6+6

No understanding; no theory Knowing how General theory of addition

  • Can add small numbers
  • More mistakes with larger numbers
  • Addition makes numbers bigger

Understanding; a theory

Gilbert Ryle (1949): Knowing How and Knowing That

theory ≈ model

12

slide-13
SLIDE 13

Understanding software

Knowing that Memorized facts

  • The Foo module handles reporting
  • It uses Angular 2
  • 25k LOC

No understanding; no theory Knowing how Understanding of the program

  • Can give impromptu “chalk talk”

about any aspect of the program

  • Zooms in or out
  • Knows what works well vs what is

kluged

13

slide-14
SLIDE 14

Theory building in science

while (true) {

  • bserve world;

if (surprise) {refactor theory}; }

  • bservations

future past

Refactor the theory

14

slide-15
SLIDE 15

Theory building in science

  • Over time, tune theory to match observations
  • Goal: theory matches future observations

How well I understand ≈ How well theory matches future observations

  • bservations

future past

Refactor the theory

15

slide-16
SLIDE 16

Theory building in programming

while (true) { pick up new requirement; if (surprise) {refactor theory}; }

requirements future past

Refactor the theory

16

slide-17
SLIDE 17

Theory building in programming

  • Over time, tune program to satisfy requirements
  • Goal: avoid “dead ends”, program can always be adapted to next requirement

requirements future past

Refactor the theory

17

slide-18
SLIDE 18

Better understanding Worse understanding

Elegant theories are better

18

slide-19
SLIDE 19

DDD breakthrough

Eric Evans, Domain Driven Design, 2004

19

slide-20
SLIDE 20

[P]rogramming properly should be regarded as an activity by which the programmers form or achieve a certain kind of insight, a theory, of the matters at hand. This suggestion is in contrast to what appears to be a more common notion, that programming should be regarded as a production of a program and certain

  • ther texts.

Peter Naur (1985) Programming as Theory Building

20

slide-21
SLIDE 21

[P]rogramming should be regarded as a production

  • f a program and certain
  • ther texts.

Every feature we add to this geocentric model makes it harder to add the next feature!

Programming without theory building

21

slide-22
SLIDE 22

Example behavior with/without models

Without models 1. Get new requirement 2. Write test case 3. Edit code minimally so test passes 4. Refactor to remove code duplication With models 1. Get new requirement 2. Does it challenge our models? a. E.g., client-server still OK? b. E.g., domain model still OK? 3. Revise models 4. Write test case 5. Revise code to match model

22

slide-23
SLIDE 23

Building theories!

23

slide-24
SLIDE 24

Programming is distributed cognition

24

slide-25
SLIDE 25

Long division

?????

  • 45 | 13095

25

slide-26
SLIDE 26

Long division

2??

  • 45 | 13095

90

  • 40

26

slide-27
SLIDE 27

Long division

29?

  • 45 | 13095

90

  • 409

405

  • 4

27

slide-28
SLIDE 28

Long division

291

  • 45 | 13095

90

  • 409

405

  • 45

45 With scribbles on paper, we can solve problems that don’t fit in our heads

28

slide-29
SLIDE 29

Distributed cognition

  • Distributed cognition is solving

problems with “scribbles on paper”

  • It can amplify cognitive ability

29

slide-30
SLIDE 30

Distributed cognition

  • Distributed cognition is solving

problems with “scribbles on paper”

  • It can amplify cognitive ability
  • Programming requires it

○ What size program can you write in your head?

  • Source code is our “scribbles”

(our external representation)

30

slide-31
SLIDE 31

Internal - external model alignment

?????

  • 45 | 13095

But not just any scribbles

31

slide-32
SLIDE 32

Roman numerals, really?

???????

  • XLV | XIIIXCV

32

slide-33
SLIDE 33

Arabic numerals, unhelpful positions

4 3 5 1 0 9 5

33

slide-34
SLIDE 34

Misaligned models = poor performance

Diagram from Stroop effect, not long division

34

slide-35
SLIDE 35

Fragile magic

Distributed cognition is fragile: “[D]ifferent representations

  • f a problem can have

dramatic impact on problem difficulty even if the formal structures are the same.”

  • - Jaijie Zhang and Donald Norman 1994

35

slide-36
SLIDE 36

You and your scribbles

  • It’s a magic trick

○ You + the scribbles

  • It is fragile

○ Bad scribbles --> trick fails

  • If it’s just you then

○ Use whatever scribbles you want ○ Write whatever code works for you ... what if you are on a team?

36

slide-37
SLIDE 37

Teamwork + external representation

291

  • 45 | 13095

90

  • 409

405

  • 45

45 Ann Bob Carl Diane

37

slide-38
SLIDE 38

How do teams steer ships?

38

slide-39
SLIDE 39

Challenge 1: Internal-external

  • Make sense of external representation

(charts, logs, …) Challenge 2: Team

  • No one person knows everything
  • Team shares external representations

Challenges

39

slide-40
SLIDE 40

Challenge 1: Internal-external

  • Make sense of external representation

(charts, logs, …) Challenge 2: Team

  • No one person knows everything
  • Team shares external representations

Success requires:

  • Good theories / models
  • Good external representations
  • Compatible models across team

Success factors

40

slide-41
SLIDE 41

Where are we?

  • Talked about theory building

○ Parallels between science and programming

  • Talked about distributed cognition

○ Can solve bigger problems with a pencil ○ … but only if models align between paper and head

  • So … what are our models / theories?

41

slide-42
SLIDE 42

Software models / theories

42

slide-43
SLIDE 43

3 categories of models

43

Domain Solution Math, logic, & friends

slide-44
SLIDE 44

3 categories of models

44

Domain What your subject matter experts talk about Often: nouns, verbs, and relationships between them Long history in

  • bject-oriented

programming Solution Math, logic, & friends

slide-45
SLIDE 45

3 categories of models

45

Domain What your subject matter experts talk about Often: nouns, verbs, and relationships between them Long history in

  • bject-oriented

programming Solution The tech known only by software engineers

  • Design patterns
  • Architecture models
  • Coding styles
  • Databases,

event queues, data structures Math, logic, & friends

slide-46
SLIDE 46

3 categories of models

46

Domain What your subject matter experts talk about Often: nouns, verbs, and relationships between them Long history in

  • bject-oriented

programming Solution The tech known only by software engineers

  • Design patterns
  • Architecture models
  • Coding styles
  • Databases,

event queues, data structures Math, logic, & friends Theories known across sciences and philosophy

  • Logic
  • Set theory
  • Category theory
  • Metamodeling

Libraries in every language; core of functional programming

slide-47
SLIDE 47

If you think it, express it in code

Code bridges internal and external

  • Code is the “scribbles on paper”

Remember:

  • Challenge 1: Internal-external
  • Challenge 2: Team

47

Keep the magic trick working

slide-48
SLIDE 48

Show all 3 models in code

Domain

  • Ubiquitous language
  • Data structure, object, & function names

Solution

  • Pattern names appear in code
  • Revealing architecture in code

Math, logic, & friends

  • First class functions
  • Use the libraries!

○ Sets.difference, not the spelled-out equivalent

48

slide-49
SLIDE 49

Reusable and ad hoc models

Reusable models Ad hoc models Domain

  • Industry standard ontologies
  • Your domain model

Solution

  • Patterns

(gang of 4 book)

  • “Programming styles” book

(Cristina Videira Lopes)

  • Your patterns
  • Your styles

Math, logic, & friends

  • Logic, set theory,

category theory, metamodeling

  • Rare

49

slide-50
SLIDE 50

The “von Neumann architecture”

50

slide-51
SLIDE 51

Link your code to those models in books

Imagine helping a friend’s startup, doing “design recovery” You are recognizing existing patterns / models

  • “Hey, it looks like your system, broadly speaking, has 3 tiers …”
  • “Is it reasonable to group these boxes as related to batch processing?”
  • “Can you point out which boxes have persistent state, which are stateless?”

Reusable models must be linked (Sitting in a book they do nothing)

51

slide-52
SLIDE 52

Models and your project

  • What are the important models for your team?
  • Where do they live?

○ Speech, whiteboards, docs, code?

  • How do they fit into your process?

○ When do you update them? ○ How strict are you?

52

Different projects, different answers

slide-53
SLIDE 53

Model-Minded Development

53

slide-54
SLIDE 54

Example behavior with/without models

Without models 1. Get new requirement 2. Write test case 3. Edit code minimally so test passes 4. Refactor to remove code duplication With models 1. Get new requirement 2. Does it challenge our models? a. E.g., client-server still OK? b. E.g., domain model still OK? 3. Revise models 4. Write test case 5. Revise code to match model

54

slide-55
SLIDE 55

Goal: “Balanced” systems and models

Systems and models ready for the next requirement

requirements future past

55

Refactor the theory

slide-56
SLIDE 56

Challenge 1: Internal-external

  • Make sense of external representation

(charts, logs, …) Challenge 2: Team

  • No one person knows everything
  • Team shares external representations

Success requires:

  • Good theories / models
  • Good external representations
  • Compatible models across team

Software teams

56

slide-57
SLIDE 57

3 categories of models

57

Domain What your subject matter experts talk about Often: nouns, verbs, and relationships between them Long history in

  • bject-oriented

programming Solution The tech known only by software engineers

  • Design patterns
  • Architecture models
  • Coding styles
  • Databases,

event queues, data structures Math, logic, & friends Theories known across sciences and philosophy

  • Logic
  • Set theory
  • Category theory
  • Metamodeling

Libraries in every language; core of functional programming

slide-58
SLIDE 58

Model-Minded Development

George Fairbanks GOTO Berlin 10 November 2016

58