Simplicity

113
simplicity 0.3 Osvaldas Grigas [email protected]

description

Building working software is hard. But it's so much harder to build software that is easy to change. Yet this is a prerequisite for being truly agile, and a key enabler of agility is simplicity. But what exactly does simplicity mean and why is it so hard to achieve? It looks like complexity creeps in as soon as you stop paying attention, and most of it is accidental. Luckily, there are practical ways to get to simplicity by following good design principles and choosing simpler tools.

Transcript of Simplicity

Page 1: Simplicity

simplicity 0.3

Osvaldas [email protected]

Page 2: Simplicity

complexity 0.3

Osvaldas [email protected]

Page 3: Simplicity

inspired by

DanNorth

RichHickey

J.B. Rainsberger

Michael Feathers

Page 4: Simplicity

Edsger Dijkstra (1980)

Computing's central challenge,"How not to make a mess of it",

has not been met.

Page 5: Simplicity

agile

Page 6: Simplicity

agile

continuous improvementbased on frequent feedback

Page 7: Simplicity

iterative development

Page 8: Simplicity
Page 9: Simplicity
Page 10: Simplicity
Page 11: Simplicity
Page 12: Simplicity
Page 13: Simplicity

incremental development

Page 14: Simplicity
Page 15: Simplicity
Page 16: Simplicity
Page 17: Simplicity
Page 18: Simplicity
Page 19: Simplicity
Page 20: Simplicity

DONE

Page 21: Simplicity

embrace the transient natureof your code

Page 22: Simplicity

Russ Miles

Complexity is the silent killer of delivering change at the right time.

Page 23: Simplicity

simplicity is prerequisite for agility

Page 24: Simplicity

what is simplicity ?

Page 25: Simplicity

Nothing is more simplethan a single giant button

MacBook Wheel

Page 26: Simplicity

what "simple" isn’t ...

Page 27: Simplicity

what "simple" isn’t ...

familiar / convenient

Page 28: Simplicity

what "simple" isn’t ...

familiar / convenient

small / concise

Page 29: Simplicity

what "simple" isn’t ...

familiar / convenient

small / concise

beautiful / elegant

Page 30: Simplicity
Page 31: Simplicity

“Simplicity -- the art of maximizing the amount of work not done -- is essential.”

from the agile principles

Page 32: Simplicity

YAGNI

from the agile principles

“Simplicity -- the art of maximizing the amount of work not done -- is essential.”

Page 33: Simplicity

“Technical excellence andgood design enhances agility.”

from the agile principles

Page 34: Simplicity

Martin Fowler

Design is there to enable you tokeep changing the software easily.

Page 35: Simplicity

when it comes to design ...

Page 36: Simplicity

COMPLEXITY SUCKS

SIMPLICITY RULES

Page 37: Simplicity

COMPLEXITY SUCKS ...

Page 38: Simplicity

COMPLEXITY SUCKS ...… your brain power

Page 39: Simplicity

COMPLEXITY SUCKS ...… your brain power

Page 40: Simplicity

Rich Hickey

Once your software is of a certain size, complexity is gonna

dominate what you can do.

Page 41: Simplicity
Page 42: Simplicity
Page 43: Simplicity

essentialcomplexity

Page 44: Simplicity

essentialcomplexity

your code

Page 45: Simplicity

essentialcomplexity

your code

libra

ries

frameworks

Page 46: Simplicity

essentialcomplexity

langua

geruntime

your code

libra

ries

frameworks

Page 47: Simplicity

accidental

complexity

essentialcomplexity

Page 48: Simplicity

SIMPLICITY RULES ...

Page 49: Simplicity

SIMPLICITY RULES ...… are …

Page 50: Simplicity

SIMPLICITY RULES ...… are …

The 4 Rules of Simple Design

Page 51: Simplicity

SIMPLICITY RULES ...… are …

The 4 Rules of Simple Design1) passes all tests

Page 52: Simplicity

SIMPLICITY RULES ...… are …

The 4 Rules of Simple Design1) passes all tests

2) clear, expressive names

Page 53: Simplicity

SIMPLICITY RULES ...… are …

The 4 Rules of Simple Design1) passes all tests

2) clear, expressive names3) no duplication

Page 54: Simplicity

SIMPLICITY RULES ...… are …

The 4 Rules of Simple Design1) passes all tests

2) clear, expressive names3) no duplication4) minimal

Page 55: Simplicity

rule #4: minimal

Page 56: Simplicity

the less code,the better

Page 57: Simplicity

code folding

Page 58: Simplicity

codegenerators

Page 59: Simplicity

dependencymanagers

Page 60: Simplicity

stop typing.

think!

Page 61: Simplicity

test-first(TDD / BDD)

Page 62: Simplicity

rule #3: no duplication

Page 63: Simplicity

primitive obsession

duplication in behavior

Page 64: Simplicity

data clump

duplication in structure

Page 65: Simplicity

refactoring

Page 66: Simplicity

rule #2: clear, expressive names

Page 67: Simplicity

small, focused methods

reduce cyclomatic complexity

Page 68: Simplicity

small, focused classes

single responsibility

Page 69: Simplicity

AccountService

AccountManager

AccountHandler

AccountUtils

AccountHelper

AccountImpl

AccountData

AccountDTO

AccountInfo

AccountDetails

AccountObject

AbstractAccount

BaseAccount

CustomAccount

SimpleAccount

Page 70: Simplicity

refactoring

Page 71: Simplicity

rule #1: passes all tests

Page 72: Simplicity

unit testing

Page 73: Simplicity

testability & good design

Page 74: Simplicity

testability & good design

(but not integration tests)

Page 75: Simplicity

inheritance-based design

Page 76: Simplicity

wget -qO- http://c2.com/ | tr -cs '[:alpha:]' '\n' | sort | uniq

composition

Page 77: Simplicity

dependencies

Page 78: Simplicity

auto-import

Page 79: Simplicity

refactoringtools

Page 80: Simplicity

A

G

F

DC

introduce indirection

Page 81: Simplicity

A

B

E G

F

DC

introduce indirection

Page 82: Simplicity

A

B

E G

F

DC

followthe law of Demeter

introduce indirection

Page 83: Simplicity

modularity

Page 84: Simplicity

coupling

Page 85: Simplicity

add an interface?

Page 86: Simplicity

layered architectures

Page 87: Simplicity

add remoting?

SOAP

Page 88: Simplicity

enterprise grade decoupling?

ESB

Page 89: Simplicity

enterprise grade decoupling?

ESB

assumptions

assumptions

Page 90: Simplicity

interface segregation

Page 91: Simplicity

tell, don’t ask

high cohesion

Page 92: Simplicity

dependency inversion

role

Page 93: Simplicity

anti-corruption layer

adapter

role

Page 94: Simplicity

notify

Payment Order

Auditor

FinancialEvent

Listener

Mongo Audit Trail

log

AuditTrail

MongoAudit

Recordsinsert

Page 95: Simplicity

Payment Order

AuditDAO

AuditDAOImpl

insert

Page 96: Simplicity

further decoupling

queue

publish subscribe

Page 97: Simplicity

use cases& business rules

framework

persist

ence

fram

ewor

k

web

DB

infrastructure

messagingQUEUE

task

scheduler

WS

Page 98: Simplicity

DomainLogic

FrameworkFramework

Page 99: Simplicity

DomainLogicDomainLogic

FrameworkFramework

accidentalcomplexity

complexityleak

Page 100: Simplicity

@Entity@Table(name = "orders", schema = "com"})public class Order implements Serializable {

@Id @GeneratedValue(strategy = SEQUENCE, generator = "order_seq") @Column(name = "ID", unique = true, nullable = false) private Integer id;

@Column(name = "NUMBER", nullable = false, length = 8) private String number;

@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinTable(name = "order_items", catalog = "com", joinColumns = {@JoinColumn(name = "ORDER_ID", updatable = false, nullable = false)}, inverseJoinColumns = {@JoinColumn(name = "ITEM_ID", updatable = false, nullable = false)}) private Set<Item> items = new HashSet<Item>();

}

Page 101: Simplicity

the law of leaky abstractions

Page 102: Simplicity

home-grownframeworks

Page 103: Simplicity

libraries

Page 104: Simplicity

state& side effects

Page 105: Simplicity

values& pure functions

Page 106: Simplicity

functional style imperative style

Page 107: Simplicity

functional style

expressions

imperative style

statements

Page 108: Simplicity

functional style

expressions

immutable values

imperative style

statements

mutable state

Page 109: Simplicity

functional style

expressions

immutable values

data transformations

imperative style

statements

mutable state

side effects

Page 110: Simplicity

functional style

expressions

immutable values

data transformations

recursion &polymorphism

imperative style

statements

mutable state

side effects

looping &branching

Page 111: Simplicity

stepping out ofcomfort zone

Page 112: Simplicity

Edsger Dijkstra (1980)

Computing's central challenge,"How not to make a mess of it",

has not been met.

Page 113: Simplicity

I‘mdone