YOW West 2017 OUR SPONSORS Cost of a dependency Lee Campbell - - PowerPoint PPT Presentation

yow west 2017
SMART_READER_LITE
LIVE PREVIEW

YOW West 2017 OUR SPONSORS Cost of a dependency Lee Campbell - - PowerPoint PPT Presentation

YOW West 2017 OUR SPONSORS Cost of a dependency Lee Campbell Author of eBook and website IntroToRx.com Dev at Cashies Conference Circuit Trainer Practical Rx Project success Longevity How long will your project need to be used for? How


slide-1
SLIDE 1

YOW West 2017

OUR SPONSORS

slide-2
SLIDE 2

Cost of a dependency

slide-3
SLIDE 3

Dev at Cashies Trainer – Practical Rx

Lee Campbell

Author of eBook and website IntroToRx.com Conference Circuit

slide-4
SLIDE 4

Project success

slide-5
SLIDE 5

Longevity

How long will your project need to be used for? How long will it need to be maintained for? How long will each of it’s dependent parts be relevant for?

slide-6
SLIDE 6

Freedoms

Single man dependencies vs Fungible assets Technology lock-in vs Technology agnostic

slide-7
SLIDE 7

A case study

A COLLECTION OF EXPERIENCES

A case study

slide-8
SLIDE 8

How did it get like this?

COMPOUNDING EFFECTS

slide-9
SLIDE 9
  • 1. Single repo
slide-10
SLIDE 10

Single repo

\GUI \Server \Datastore

slide-11
SLIDE 11

Single repo

\GUI

  • FeatureA
  • FeatureB

\Server

  • FeatureA
  • FeatureB
  • Shared

\Datastore

slide-12
SLIDE 12

Single repo

\GUI

  • FeatureA
  • FeatureB
  • FeatureC

\Server

  • FeatureA
  • FeatureB
  • FeatureC
  • Shared
  • Logic
  • Scripts (Builds, Deployments)

\Datastore

slide-13
SLIDE 13

Single repo

\GUI

  • FeatureA
  • FeatureB
  • FeatureC

\Server

  • FeatureA
  • FeatureB
  • FeatureC
  • Shared
  • Logic
  • Scripts (Builds, Deployments)

\Datastore

  • FeatureA
  • FeatureB
  • FeatureC
slide-14
SLIDE 14

Single repo

\GUI

  • FeatureA
  • FeatureB
  • FeatureC
  • Shared

\Server

  • FeatureA
  • FeatureB
  • FeatureC
  • Shared
  • Logic
  • Contracts

\Framework

  • Comms Layer
  • Data Persistence abstraction
  • Scripts (Builds, Deployments)

\Datastore

  • FeatureA
  • FeatureB
  • FeatureC
slide-15
SLIDE 15

Single repo

Who defines requirements and budget for each part of the system? Can this progression be maintained for the expected lifetime of the system? Do these things change together?

slide-16
SLIDE 16

Single repo - Consequences

Build times increase Testing burden Friction to innovate Blurry boundaries Lack of responsibility

slide-17
SLIDE 17
  • 2. Depend on

abstractions

slide-18
SLIDE 18

Interface all the things

View Models Translators Validators

slide-19
SLIDE 19
slide-20
SLIDE 20
slide-21
SLIDE 21

Consequences

Testing now becomes an exercise in mocking Debugging is always a case of hitting finding "implementations of"

slide-22
SLIDE 22
slide-23
SLIDE 23
slide-24
SLIDE 24
slide-25
SLIDE 25

Consequences

Focus is diluted Cognitive load is increased through indirection

slide-26
SLIDE 26

Depend on (external) abstractions

We can also take dependencies on interface define by someone else So maybe you just mock out your

  • IoC Continer
  • SqlConnection
  • ORM UnitOfWork

But these are normally defined in their package, with the implementation.

slide-27
SLIDE 27
  • 3. Deep layering
slide-28
SLIDE 28

Deep layering

Deep system dependencies

slide-29
SLIDE 29

Deep layering

slide-30
SLIDE 30

Deep layering

My application

  • My libraries
  • My Framework
  • My Framework subsystem
  • Generic public packages
  • Low level generic public packages
slide-31
SLIDE 31

Deep layering

My application

  • My libraries (Domain, Data Access, Comms, Controls, Styles)
  • My Framework (DataAccess, Comms, Contracts, Generic Utilities, Controls, Styles)
  • My Framework subsystem (Implementation specific DataAccess, Comms etc)
  • Generic public packages (ORM, Serializers, Web Platform, Messaging, Document manipulation)
  • Low level generic public packages (Network interfaces, Collections Libraries)
slide-32
SLIDE 32

Deep layering

Non linear growth 3 deep with each dependency having 3 children 1 + 3 + 9 = 13 total

slide-33
SLIDE 33

Deep layering

Non linear growth Add 2 more layers (5 layers) 1 + 3 + (9 * 13) = 121 total

1 1 1 1 13 13 13 13 13 13 13 13 13

slide-34
SLIDE 34

Deep layering

Non linear growth Add 2 more layers (7 layers) 1 + 3 + (9 * 121) = 1093 total

1 1 1 1 121 121 121 121 121 121 121 121 121

slide-35
SLIDE 35

+ baggage

Packages that include

  • minified and original resource
  • Documentation (JavaDoc/Intellisense)
  • Tooling
slide-36
SLIDE 36

Deep call stacks

I depend on abstractions But they also depend on abstractions So I have deep call stacks

slide-37
SLIDE 37

Deep call stacks

https://twitter.com/gregyoung/status/ 734713437146734592

slide-38
SLIDE 38
slide-39
SLIDE 39

Consequences

Cognitive load increases exponentially with each layer Technical freedom is slowly eroded as each layer add more dependencies

slide-40
SLIDE 40

Compounding Consequences

slide-41
SLIDE 41

Compounding consequences

Build times Test times Lack of Ownership

slide-42
SLIDE 42

Compensating behaviour

Magic Build scripts Using the real IoC Container in tests AOP

slide-43
SLIDE 43

Complicated becomes complex

Cant be rationalised about Emergent behaviour (bugs, not features)

slide-44
SLIDE 44

Alternatives

IS THERE A BETTER WAY?

slide-45
SLIDE 45

Single repo

FEATURE DEPENDENCY

slide-46
SLIDE 46

If it changes together, it lives together

Ways to identify

  • The person that has final say on requirements is different
  • Release cadences are different
  • Code change cadence is different
  • Failures are ignored

"Decompose your applications based on volatility" - Juval Lowy

slide-47
SLIDE 47

Single repo

\GUI

  • FeatureA
  • FeatureB
  • FeatureC
  • Shared

\Server

  • FeatureA
  • FeatureB
  • FeatureC
  • Shared
  • Logic
  • Contracts

\Framework

  • Comms Layer
  • Data Persistence abstraction
  • Scripts (Builds, Deployments)

\Datastore

  • FeatureA
  • FeatureB
  • FeatureC
slide-48
SLIDE 48

Multi repo

FeatureA

  • GUI
  • Server
  • DataStore
  • Contracts

FeatureB

  • GUI
  • Server
  • DataStore
  • Contracts

FeatureC

  • GUI
  • Server
  • DataStore
  • Contracts

GUI Lib Comms Lib Persistence Lib

slide-49
SLIDE 49

Multi repo

Inherently parallel to build and test Forces the discussion about design by contract Can reduce the knee jerk reaction to share code

slide-50
SLIDE 50

Encapsulation

slide-51
SLIDE 51

Justify the interface

What is the benefit of this being injected? Can it be encapsulated into this unit?

slide-52
SLIDE 52
slide-53
SLIDE 53

Private by default

Instead of Reuse being a goal, aim for encapsulation. Rule of 3 Reuse is an evolution

slide-54
SLIDE 54

The snip rule

Avoid dependencies that require finesse to remove Single line to cut

slide-55
SLIDE 55

Code in action

A DOMAIN MODEL WITH NO DEPENDENCIES

slide-56
SLIDE 56

Only depends on .NET

slide-57
SLIDE 57

So how does it do anything

The Domain Model defines the interfaces for the things it needs

  • IRepository<T>

Can you tell what technology we are using here? Consumers are responsible to implement it We are isolating the business logic from our technology choices.

slide-58
SLIDE 58

Inversion of Control

slide-59
SLIDE 59

Hosts compose shallow dependencies

Hexagonal Architecture (Alistair Cockburn)  Ports and Adapters  Onion Architecture

slide-60
SLIDE 60

We define our Ports

IRepository is one of our ports We may have a SQLServer adapter, or perhaps a MongoDB one

slide-61
SLIDE 61

Composition

App Service Domain Model

Data Service

ORM Data store

Comms Service

Serialization Messaging platform

slide-62
SLIDE 62

Composition

Domain Model Comms adapter Data adapter App Service Data store Comms

slide-63
SLIDE 63

Adapters

CODE BREAK OUT

slide-64
SLIDE 64

Composition instead of AOP

I can just use normal old Decorator pattern

slide-65
SLIDE 65

Results

Multi repo

  • Division of labour
  • Cohesive code base
  • Reduced cognitive load
  • Technical freedom
slide-66
SLIDE 66

Results

Encapsulation

  • Reduced cognitive load
  • Less busy work
  • Snip rule
slide-67
SLIDE 67

Results

Inversion of Dependencies / Ports and Adapter

  • Focused code
  • Fast tests
  • Shallow stacks
  • Technical Freedom
slide-68
SLIDE 68

Know your costs

Cognitive load Onboarding friction Technical Freedom Time to prod

slide-69
SLIDE 69

More information

LeeCampbell.com Implementing Domain Driven Design – Vaugh Vernon Greg Young – Good enough software Hex Arch – Alistair Cockburn

Having the computer to do what you want isn’t the hard part, having a person understand the intent of your code is.