Top Banner
Eager Design by @_md marcello duarte Introducing
96

Introducing Eager Design

Jan 14, 2017

Download

Technology

Marcello Duarte
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introducing Eager Design

Eager Designby @_md

♞marcello duarte

Introducing

Page 2: Introducing Eager Design

marcello duarte

@_md

#EagerDesign

Page 3: Introducing Eager Design

agile is lazy

@_md#EagerDesign

Page 4: Introducing Eager Design

"Make the commitment at the last responsible moment"

Preston Smith

decide later

Page 5: Introducing Eager Design

software is about people

@_md#EagerDesign

Page 6: Introducing Eager Design

age of excess

@_md#EagerDesign

Page 7: Introducing Eager Design

subtraction

@_md#EagerDesign

Page 8: Introducing Eager Design

subtraction��� ���

@_md#EagerDesign

Page 9: Introducing Eager Design

laws of subtraction

@_md

Page 10: Introducing Eager Design

laws of subtraction

what isn’t there can often trump what is. the simplest rules create the most effective experience. limiting information engages imagination. creativity thrives under intelligent constraints. break is the important part of breakthrough. doing something isn’t always better than doing nothing.

Matthew E. May

Page 11: Introducing Eager Design
Page 12: Introducing Eager Design

Eager Design

how♞

Jump to the problem worth solving Eagerly replace primitives with types Compose [the domain algebra] inside-out Avoid mutable state

#1 #2 #3 #4

@_md#EagerDesign

Page 13: Introducing Eager Design

outside-in

Page 14: Introducing Eager Design

outside-in

unit test code

refactor

acceptance

ui/controller/views

orm, libs, domain objects

framework stuff (forms…)

model/view/controller

Page 15: Introducing Eager Design

events

outside-inUI

Domain

core

Application

Infrastructure

mobile UI

port/adapter

port/adapterDB

http

s://p

bs.tw

img.

com

/med

ia/C

HyU

AukW

gAA5

iYS.

jpg

reads

writes

Page 16: Introducing Eager Design

the right outside

http://bit.ly/modellingbyexample

http://bit.ly/whencucumbersgobad

@_md#EagerDesign

Page 17: Introducing Eager Design

{ outside-inslow misleading complex restricts composability

Page 18: Introducing Eager Design

when?

Page 19: Introducing Eager Design

Eager Designwh

endone trivial

donenot trivial

not done

no idea[based on Cynefin, Snowden 03]

@_md#EagerDesign

Page 20: Introducing Eager Design

Eager Designwh

endone trivial

donenot trivial

not done

no idea[based on Cynefin, Snowden 03]

Outside-in

@_md#EagerDesign

Page 21: Introducing Eager Design

Eager Designwh

endone trivial

donenot trivial

not done

no idea[based on Cynefin, Snowden 03]

Eager Design

Outside-in

@_md#EagerDesign

Page 22: Introducing Eager Design

Eager Designwh

endone trivial

donenot trivial

not done

no idea[based on Cynefin, Snowden 03]

Eager Design

Outside-in

¯\_(ツ)_/¯

@_md#EagerDesign

Page 23: Introducing Eager Design

Example

Page 24: Introducing Eager Design
Page 25: Introducing Eager Design

{ chess appwe add players it generates the schedule we can enter the results we can see the ranking

TRIVIA

L

TRIVIA

L

TRIVIA

L

Eager Design

@_md

Page 26: Introducing Eager Design

{ domain rulesplayers will play with every other player

players can't play twice in the same round

every player must play in every round

players must play twice with another player

@_md

Page 27: Introducing Eager Design

How do I converta list of things

into a list of unique listsof unique pairs?

Page 28: Introducing Eager Design

Let me think

Page 29: Introducing Eager Design

a b c d e f g hList of things

Page 30: Introducing Eager Design

a b c d e f g hList of things

Pairsa b c dh g f e

Page 31: Introducing Eager Design

Pairs

a b c d

h g f e

Page 32: Introducing Eager Design

Shift to the right

a b c d

h g f ee

Page 33: Introducing Eager Design

We haz roundz! :o)

a b c d

h g f ee

Page 34: Introducing Eager Design

r1 r2 r3 r4

r5 r6 r7

+r1 r2 r3 r4

r5 r6 r7

inverse( )

Page 35: Introducing Eager Design
Page 36: Introducing Eager Design

r1 r2 r3 r4

r5 r6 r7 r8

r9 r10 r11 r12

r13 r14

shuffle( )

Page 37: Introducing Eager Design
Page 38: Introducing Eager Design

laws of subtraction

what isn’t there can often trump what is. the simplest rules create the most effective experience. limiting information engages imagination. creativity thrives under intelligent constraints. break is the important part of breakthrough. doing something isn’t always better than doing nothing.

Matthew E. May

Page 39: Introducing Eager Design

#1 Jump to the problem worth solving

@_md#EagerDesign

Page 40: Introducing Eager Design

http://github.com/MarcelloDuarte/phunkie

Page 41: Introducing Eager Design

ImmList

a b c d e f g hhead

a b c d e f g htail

a b c d e f g hinit

a b c d e f g hlast

Page 42: Introducing Eager Design

concat( head($players), last($players), init(tail($players))

Page 43: Introducing Eager Design

function shift(ImmList $players){ return concat(head($players), last($players), init(tail($players)) );}

Page 44: Introducing Eager Design

function shift(ImmList $players){ return concat(head($players), last($players), init(tail($players)) );}

Page 45: Introducing Eager Design

function round(ImmList $players) { $sides = $players->splitAt($players->length/2); return $sides->_1->zip($sides->_2->reverse());}

Page 46: Introducing Eager Design

function rounds(ImmList $players) {

}

Page 47: Introducing Eager Design

function rounds(ImmList $players, $rounds = []) { $rounds[] = round($players);

return count($rounds) < $players->length - 1 ? rounds(shift($players), $rounds) : ImmList(...$rounds);}

Page 48: Introducing Eager Design

function rounds(ImmList $players, $rounds = []){ $rounds[] = round($players);

return count($rounds) < $players->length - 1 ? rounds(shift($players), $rounds) : ImmList(...$rounds);}

Page 49: Introducing Eager Design

function rounds(ImmList $players, $rounds = []){ $rounds[] = round($players);

return count($rounds) < $players->length - 1 ? rounds(shift($players), $rounds) : ImmList(...$rounds);}

Page 50: Introducing Eager Design

function rounds(ImmList $players, $rounds = []){ $rounds[] = round($players);

return count($rounds) < $players->length - 1 ? rounds(shift($players), $rounds) : ImmList(...$rounds);}

#3 Compose

Page 51: Introducing Eager Design

function rounds(ImmList $players, $rounds = []){ $rounds[] = round($players);

return count($rounds) < $players->length - 1 ? rounds(shift($players), $rounds) : ImmList(...$rounds);}

#4 Avoid mutable state

Page 52: Introducing Eager Design

function rounds(ImmList $players, $rounds = []) { $rounds[] = round($players);

return count($rounds) < $players->length - 1 ? rounds(shift($players), $rounds) : ImmList(...$rounds);}

Page 53: Introducing Eager Design

function schedule(ImmList $players) { return concat(rounds($players), inverse(rounds($players));}

Page 54: Introducing Eager Design

#2 Eagerly replace primitives with types

@_md#EagerDesign

Page 55: Introducing Eager Design

“My math background made me realise that each object could have several

algebras associated with it, and there could be families of these, and that these

would be very very useful...

Page 56: Introducing Eager Design

...I made up a term "genericity" fordealing with generic behaviours in a

quasi-algebraic form...

Page 57: Introducing Eager Design

...I didn't like the way Simula I or Simula 67 did inheritance. So I decided to leave

out inheritance as a built-in feature until I understood it better.”

Alan Kay

Page 58: Introducing Eager Design

http://bit.ly/meaning-­‐of-­‐oo

Page 59: Introducing Eager Design

type Player = string;type Players = ImmList<Player>; type Match = Pair<Player,Player> type Round = ImmList<Match>; type Rounds = ImmList<Round>; type Schedule = Rounds;

Page 60: Introducing Eager Design
Page 61: Introducing Eager Design

function shift(Players $players): Players{ return concat(head($players), last($players), init(tail($players)) );}

Page 62: Introducing Eager Design

function round(Players $players): Round { $sides = $players->splitAt($players->length/2); return $sides->_1->zip($sides->_2->reverse());}

Page 63: Introducing Eager Design

function rounds(Players $players, $rounds = []) : Rounds{ $rounds[] = round($players);

return count($rounds) < $players->length - 1 ? rounds(shift($players), $rounds) : ImmList(...$rounds);}

Page 64: Introducing Eager Design

function schedule(Players $players): Rounds { return concat(rounds($players), inverse(rounds($players));}

Page 65: Introducing Eager Design

Compose the domain algebra inside-out

@_md#EagerDesign

Page 66: Introducing Eager Design

namespace Md\Chess\ScheduleGeneration;

shift(Players $players): Players round(Players $players): Roundrounds(Players $players): Roundsschedule(Players $players): Schedule

Page 67: Introducing Eager Design

Players => Schedule

Page 68: Introducing Eager Design

Players => Rounds => Schedule

Page 69: Introducing Eager Design

Players => Round => Rounds => Schedule

Page 70: Introducing Eager Design

domain rules are defined against types

@_md#EagerDesign

Page 71: Introducing Eager Design

{ domain rulesplayers will play with every other player

players can't play twice in the same round

every player must play in every round

players must play twice with another player

@_md

Page 72: Introducing Eager Design

rich domain model vs lean domain model

Page 73: Introducing Eager Design

S

S

S

S

S

S

@_md#EagerDesign

rich domain

Page 74: Introducing Eager Design

Immu

table S

tate

Immu

table S

tate

Immu

table S

tate

B B

lean domain

Laws

Page 75: Introducing Eager Design

Interpreting Services Agency

Example

@_md#EagerDesign

Page 76: Introducing Eager Design

def request def decline def amend def accept def done

Page 77: Introducing Eager Design

def request(details:JobDetails): Job def decline(ref:JobRef): Job def amend(details:JobDetails): Job => Option[TimeSheet] def accept(ref:JobRef): Job => Option[TimeSheet] def done(ref:JobRef): TimeSheet => Remittance

Page 78: Introducing Eager Design

trait JobService

{ def request(details:JobDetails): Job def decline(ref:JobRef): Job def amend(details:JobDetails): Job => Option[TimeSheet] def accept(ref:JobRef): Job => Option[TimeSheet] def done(ref:JobRef): TimeSheet => Remittance

}

Page 79: Introducing Eager Design

trait JobService

{ def request(details:JobDetails): Job def decline(ref:JobRef): Job def amend(details:JobDetails): Job => Option[TimeSheet] def accept(ref:JobRef): Job => Option[TimeSheet] def done(ref:JobRef): TimeSheet => Remittance

}

Page 80: Introducing Eager Design

f(a:A):M[B]

g(a:B):M[C]

Page 81: Introducing Eager Design

f(a:A):M[B]

f(a) map g = M[M[C]]

g(a:B):M[C]

Page 82: Introducing Eager Design

f(a:A):M[B]

join f(a) map g = M[C]

g(a:B):M[C]

Page 83: Introducing Eager Design

f(a:A):M[B]

andThen

g(a:B):M[C]

Page 84: Introducing Eager Design

request andThenamend andThendone

Page 85: Introducing Eager Design

def execute(input:Input): Unit path = input("path").getOrElse("specs")

loadSpecs(path) andThen runSpecs andThen presentResults

Page 86: Introducing Eager Design

what’s the eager point?

@_md#EagerDesign

Page 87: Introducing Eager Design
Page 88: Introducing Eager Design

merging 2 cells!!

@_md#EagerDesign

Page 89: Introducing Eager Design

{ 3 casessame value different value right hand side is empty

Page 90: Introducing Eager Design

if ($this->value == $another->value) {

return Pair(Cell(), Cell($this->value + $another->value));

} elseif ($another->isEmpty()) {

return Pair(Cell(), Cell($this->value));

}

return Pair(Cell($this->value), Cell($another->value));

Page 91: Introducing Eager Design

if ($this->value == $another->value) {

return Pair(Cell(), Cell($this->value + $another->value));

} elseif ($another->isEmpty()) {

return Pair(Cell(), Cell($this->value));

}

return Pair(Cell($this->value), Cell($another->value));

Page 92: Introducing Eager Design

if ($this->value == $another->value) {

return Pair(Cell(), Cell($this->value + $another->value));

} elseif ($another->isEmpty()) {

return Pair(Cell(), Cell($this->value));

}

return Pair(Cell($this->value), Cell($another->value));

Page 93: Introducing Eager Design

function swipe($lines){ return $lines->map(function ($line) { $lineCopy = mergeLine($line);

while (!isLineMerged($lineCopy)) { $lineCopy = mergeLine($lineCopy); }

return $lineCopy; }); }

Page 94: Introducing Eager Design

Eager Design

Jump to the problem worth solving Eagerly replace primitives with types Compose [the domain algebra] inside-out Avoid mutable state

#1 #2 #3 #4

@_md#EagerDesign

Page 95: Introducing Eager Design

marcello duarte

@_md

#EagerDesign

Page 96: Introducing Eager Design

Thank you!

@_md

bit.ly/inviqa-contact bit.ly/inviqa-careers

#EagerDesign