simplicity 0.3
Osvaldas [email protected]
complexity 0.3
Osvaldas [email protected]
inspired by
DanNorth
RichHickey
J.B. Rainsberger
Michael Feathers
Edsger Dijkstra (1980)
Computing's central challenge,"How not to make a mess of it",
has not been met.
agile
agile
continuous improvementbased on frequent feedback
iterative development
incremental development
DONE
embrace the transient natureof your code
Russ Miles
Complexity is the silent killer of delivering change at the right time.
simplicity is prerequisite for agility
what is simplicity ?
Nothing is more simplethan a single giant button
MacBook Wheel
what "simple" isnt ...
what "simple" isnt ...
familiar / convenient
what "simple" isnt ...
familiar / convenient
small / concise
what "simple" isnt ...
familiar / convenient
small / concise
beautiful / elegant
Simplicity -- the art of maximizing the amount of work not done -- is essential.
from the agile principles
YAGNI
from the agile principles
Simplicity -- the art of maximizing the amount of work not done -- is essential.
Technical excellence andgood design enhances agility.
from the agile principles
Martin Fowler
Design is there to enable you tokeep changing the software easily.
when it comes to design ...
COMPLEXITY SUCKS
SIMPLICITY RULES
COMPLEXITY SUCKS ...
COMPLEXITY SUCKS ... your brain power
COMPLEXITY SUCKS ... your brain power
Rich Hickey
Once your software is of a certain size, complexity is gonna
dominate what you can do.
essentialcomplexity
essentialcomplexity
your code
essentialcomplexity
your code
libra
ries
frameworks
essentialcomplexity
langua
geruntime
your code
libra
ries
frameworks
accidental
complexity
essentialcomplexity
SIMPLICITY RULES ...
SIMPLICITY RULES ... are
SIMPLICITY RULES ... are
The 4 Rules of Simple Design
SIMPLICITY RULES ... are
The 4 Rules of Simple Design1) passes all tests
SIMPLICITY RULES ... are
The 4 Rules of Simple Design1) passes all tests
2) clear, expressive names
SIMPLICITY RULES ... are
The 4 Rules of Simple Design1) passes all tests
2) clear, expressive names3) no duplication
SIMPLICITY RULES ... are
The 4 Rules of Simple Design1) passes all tests
2) clear, expressive names3) no duplication4) minimal
rule #4: minimal
the less code,the better
code folding
codegenerators
dependencymanagers
stop typing.
think!
test-first(TDD / BDD)
rule #3: no duplication
primitive obsession
duplication in behavior
data clump
duplication in structure
refactoring
rule #2: clear, expressive names
small, focused methods
reduce cyclomatic complexity
small, focused classes
single responsibility
AccountService
AccountManager
AccountHandler
AccountUtils
AccountHelper
AccountImpl
AccountData
AccountDTO
AccountInfo
AccountDetails
AccountObject
AbstractAccount
BaseAccount
CustomAccount
SimpleAccount
refactoring
rule #1: passes all tests
unit testing
testability & good design
testability & good design
(but not integration tests)
inheritance-based design
wget -qO- http://c2.com/ | tr -cs '[:alpha:]' '\n' | sort | uniq
composition
dependencies
auto-import
refactoringtools
AG
F
DC
introduce indirection
AB
E G
F
DC
introduce indirection
AB
E G
F
DC
followthe law of Demeter
introduce indirection
modularity
coupling
add an interface?
layered architectures
add remoting?
SOAP
enterprise grade decoupling?
ESB
enterprise grade decoupling?
ESB
assumptions
assumptions
interface segregation
tell, dont ask
high cohesion
dependency inversion
role
anti-corruption layer
adapter
role
notify
Payment Order Auditor
FinancialEvent
Listener
Mongo Audit Trail
log
AuditTrail
MongoAudit
Recordsinsert
Payment Order
AuditDAO
AuditDAOImpl
insert
further decoupling
queue
publish subscribe
use cases& business rules
framew
ork
persist
ence
fram
ewor
k
web
DB
infrastructure
messagingQUEUE
task
scheduler
WS
DomainLogic
FrameworkFramework
DomainLogicDomainLogic
FrameworkFramework
accidentalcomplexity
complexityleak
@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 items = new HashSet();
}
the law of leaky abstractions
home-grownframeworks
libraries
state& side effects
values& pure functions
functional style imperative style
functional style
expressions
imperative style
statements
functional style
expressions
immutable values
imperative style
statements
mutable state
functional style
expressions
immutable values
data transformations
imperative style
statements
mutable state
side effects
functional style
expressions
immutable values
data transformations
recursion &polymorphism
imperative style
statements
mutable state
side effects
looping &branching
stepping out ofcomfort zone
Edsger Dijkstra (1980)
Computing's central challenge,"How not to make a mess of it",
has not been met.
Imdone