sand piles and software - madison ruby conference

82
Sand Piles and Software Zach Dennis

Upload: zach-dennis

Post on 27-Jun-2015

769 views

Category:

Technology


0 download

DESCRIPTION

This is a slightly varied version my previous Sand Piles and Software talk for the Madison Ruby Conference. Instead of including slides on the values, it incorporates a second part which is dedicated to decision making and some concrete areas where we can learn to help improve how we make decisions with code.

TRANSCRIPT

Page 1: Sand Piles and Software - Madison Ruby Conference

Sand Piles and

Software

Zach Dennis

Page 2: Sand Piles and Software - Madison Ruby Conference
Page 3: Sand Piles and Software - Madison Ruby Conference

Part I

Page 4: Sand Piles and Software - Madison Ruby Conference

Bak-Tang-Wiesenfeld

Sand Pile Model

Page 5: Sand Piles and Software - Madison Ruby Conference

macro

from themicro

Page 6: Sand Piles and Software - Madison Ruby Conference
Page 7: Sand Piles and Software - Madison Ruby Conference

What eventually happens if you keep dropping grains of

sand?

Page 8: Sand Piles and Software - Madison Ruby Conference

Itla

ndslid

es.

Page 9: Sand Piles and Software - Madison Ruby Conference

Systems can only sustain so much stress.

Page 10: Sand Piles and Software - Madison Ruby Conference

self-organized criticalityA property of a system that has a critical

state (point) as an attractor.

Page 11: Sand Piles and Software - Madison Ruby Conference

Software is attracted to its critical point.

critical point

Functionality

Com

plex

ity

Page 12: Sand Piles and Software - Madison Ruby Conference

Xsoftware is not linear

Page 13: Sand Piles and Software - Madison Ruby Conference

Software is attracted to its critical point.

critical point

Functionality

Com

plex

ity

Page 14: Sand Piles and Software - Madison Ruby Conference

software is non-linear

Page 15: Sand Piles and Software - Madison Ruby Conference

Software feeds back into itselfSx = ... (Sx - 1)

Page 16: Sand Piles and Software - Madison Ruby Conference

0.2 compared to 0.2000000001

Page 17: Sand Piles and Software - Madison Ruby Conference

critical point

Functionality

Com

plex

ity

Page 18: Sand Piles and Software - Madison Ruby Conference

What we don’t want.

Page 19: Sand Piles and Software - Madison Ruby Conference

Balanced and Distributed

Page 20: Sand Piles and Software - Madison Ruby Conference

Sand Piles and Sand Boxes

Page 21: Sand Piles and Software - Madison Ruby Conference

The Vicious Stop n Go.

Vicious Stop / Go Cycle

critical point

Functionality

Com

plex

ity

Page 22: Sand Piles and Software - Madison Ruby Conference

The Vicious Stop n Go.

More effort initially.

critical point

Functionality

Com

plex

ity

Page 23: Sand Piles and Software - Madison Ruby Conference

The Vicious Stop n Go.

Smaller apps get away with it.

critical point

Functionality

Com

plex

ity

small app large app

Page 24: Sand Piles and Software - Madison Ruby Conference

Performance = Complexity(Process) * Team * Tools

Page 25: Sand Piles and Software - Madison Ruby Conference

bad processes amplify complexity

good processes dampen it

Page 26: Sand Piles and Software - Madison Ruby Conference

How do we keep software away from its critical point?

Page 27: Sand Piles and Software - Madison Ruby Conference

Part II

Page 28: Sand Piles and Software - Madison Ruby Conference

Optimized decision making

pathways

Page 29: Sand Piles and Software - Madison Ruby Conference

def solve_problem(problem, knowledge) if quick_fix(problem).possible? quick_fix.go! else solve_problem problem, learn(problem) endend

Page 30: Sand Piles and Software - Madison Ruby Conference

Problem Understanding

RandomAttempts Quick fix Intentional Nailed it

None LittleGood

Amount A lot

Solution

Page 31: Sand Piles and Software - Madison Ruby Conference

If you do ______________ today,you’ll likely do ___________ tomorrow.

If you don’t do ______________ today,you’ll likely won’t do ___________ tomorrow.

Page 32: Sand Piles and Software - Madison Ruby Conference

Our brains don’t compute probabilitiesand then choose the best possible outcome

when it can avoid it.

Page 33: Sand Piles and Software - Madison Ruby Conference
Page 34: Sand Piles and Software - Madison Ruby Conference
Page 35: Sand Piles and Software - Madison Ruby Conference
Page 36: Sand Piles and Software - Madison Ruby Conference

DailyCheeper#cheep!

File System

Person Subscription

Mobile Push Library - know about where and how to load cheeps

data- know about how person is related to - know about subscriptions- know about time zone conversion- know about about to use mobile push library- localizations???

Cheeps Data

Structure

Dependencies

Page 37: Sand Piles and Software - Madison Ruby Conference
Page 38: Sand Piles and Software - Madison Ruby Conference

DailyCheeper#cheep!

Person Subscription

Mobile Push Library

- knows how to use cheeps data

- knows how to use Person interface to find eligible subscribers

- knows how to use mobile push library

Cheeps File System

- message_for_day- localization for accessing cheeps

- knows how to determine eligibility based on subscription

Dependencies after balancing responsibilities

Page 39: Sand Piles and Software - Madison Ruby Conference

Let’s improve our decision pathways

Page 40: Sand Piles and Software - Madison Ruby Conference

Domain complexity

Conceptual complexity

Code complexity

Page 41: Sand Piles and Software - Madison Ruby Conference

Properties and conceptsfor practical application

CohesionCouplingConnassenceEntanglement

Exposing Crisp Abstractions / ConceptsTestability

Responsibility / Dependencies / Collaborators / Boundaries

Composition InheritanceMixins

Naming, ConceptsShared UnderstandingPattern Language

Reflection

Page 42: Sand Piles and Software - Madison Ruby Conference

the focus of an individual software component given its function or purpose to exist

Cohesion

Array#pushArray#popArray#[]Array#countArray#<<

Cheeper#delivery_dailyCheeper#delivery_weeklyCheeper#deliver_monthly

Cheeps#loadCheeps#addCheeps#saveCheeps#remove

Page 43: Sand Piles and Software - Madison Ruby Conference

Not very cohesive

Page 44: Sand Piles and Software - Madison Ruby Conference

Separating out concepts

Page 45: Sand Piles and Software - Madison Ruby Conference

The relationship between software components, the extent to which a component of our software depends

on other components.

Coupling

DailyCheeper#cheep!

File System

Person Subscription

Mobile Push Library

Cheeps Data

Structure

Page 46: Sand Piles and Software - Madison Ruby Conference
Page 47: Sand Piles and Software - Madison Ruby Conference
Page 48: Sand Piles and Software - Madison Ruby Conference

a single measure combining coupling and cohesion, measured in terms of strength or weakness (preferred)

Connassence

Name

Type

Meaning

Position

Algorithm

Execution

Timing

Identity http://onestepback.org/articles/connascence/index.html

http://vimeo.com/10837903

http://en.wikipedia.org/wiki/Connascent_software_components

weaker

stronger

Page 49: Sand Piles and Software - Madison Ruby Conference
Page 50: Sand Piles and Software - Madison Ruby Conference

Making concepts and abstractions in your application (technical or domain related) first-class citizens.

Being explicit

Page 51: Sand Piles and Software - Madison Ruby Conference

Extracting a Concept w/a distinct responsibility

Page 52: Sand Piles and Software - Madison Ruby Conference
Page 54: Sand Piles and Software - Madison Ruby Conference

Rake

ActiveModel::Validations

ActiveRecord::Relation

ActionController filters (orthogonality)

Whenever (gem)

Capybara

Page 55: Sand Piles and Software - Madison Ruby Conference

http://en.wikipedia.org/wiki/Directed_acyclic_graph

Directed Acyclic Graph

Page 56: Sand Piles and Software - Madison Ruby Conference

Testable components are typically simpler components.

Testability

Page 57: Sand Piles and Software - Madison Ruby Conference

Testability- simpler objects

- simpler interfaces

- lower number of unnecessary dependencies

- push external system interaction to the edge, isolate when possible

- remove unnecessary conditionals when possible

- promotes simpler code and more distributed, balanced set of responsibilities

- stub less, mock less, spy only when necessary

Page 58: Sand Piles and Software - Madison Ruby Conference

Testability

Page 59: Sand Piles and Software - Madison Ruby Conference

- Write a statement describing the responsibility a class or module. If there are a bunch of ANDs consider it suspicious.

- Identify “what” your object needs to fulfill that responsibility

- Identify your collaborators to meet those needs

- Identify boundaries for primary dependencies and everything else

Responsibility / Dependencies / Collaborators / Boundaries

Page 60: Sand Piles and Software - Madison Ruby Conference

Good statement:## The DailyCheeper is responsible for sending mobile notifications via SMS# to people have subscribed to them.#

Suspicious statement:## The DailyCheeper is responsible for sending mobile notifications via SMS# to people have subscribed to them, building reports around cheeps statistics,# subscribing users to cheeps, and updating/saving cheeps.#

Page 61: Sand Piles and Software - Madison Ruby Conference

Dependencies list:

- find people who are eligible and have subscribed to receiving cheeps for given time

- take into account timezones

- find out if locales/translations are necessary

- get/retrieve access to today’s cheep to send

- mobile library for sending out cheeps - access to device_id (can get off from person)

Page 62: Sand Piles and Software - Madison Ruby Conference

DailyCheeper

Person

Cheeps

Load Cheeps from FileSystem

Mobile Push Library

SubscriptionPrimary collaboratorsSecondary collaborators

Identify collaborators

Page 63: Sand Piles and Software - Madison Ruby Conference

DailyCheeper

Person

Cheeps

Load Cheeps from FileSystem

Mobile Push Library

Subscription

Unit testing scope

Identify boundaries

Page 64: Sand Piles and Software - Madison Ruby Conference

DailyCheeper

Person

Cheeps

Load Cheeps from FileSystem

Mobile Push Library

Subscription

Unit testing scope

Identify boundaries

Page 65: Sand Piles and Software - Madison Ruby Conference

- Semantic

- Appropriate for level of abstraction

- Classes, modules, methods, variables

- Avoid redundancy, ambiguity

Naming, Concepts

CustomersController#create

Customer#create

ConnectionPool#connection

MySQLAdapter#insert_sql

Page 66: Sand Piles and Software - Madison Ruby Conference

- Make conventions and patterns an explicit part of your vocabulary

- Make them up, or re-use useful patterns, etc you’ve found

- Evaluate, share, teach, learn

Shared Understanding / Pattern Languages

Page 67: Sand Piles and Software - Madison Ruby Conference

- Ruby module pattern for inheritance (for chaining behavior in a loosely coupled way, ie: ActiveRecord uses this pattern a lot when for #save)

- Constructor injection (for providing defaults but allowing object to be more easily testable)

- Boundaries (for creating a clear distinction between one part of the application and another, ie: Api, Kernel, and Border)

- Splatting/flattening conditionals (to indicate a conditional, branch of code, should not exist, investigate ways to remove it)

- Everything’s private until it’s public

- No class variables (they should be banished)

A few we use:

Page 68: Sand Piles and Software - Madison Ruby Conference

Ruby module pattern example

Page 69: Sand Piles and Software - Madison Ruby Conference

Boundaries example (API/Library)

Intuit::Api Intuit::Kernel Intuit::Border

CustomerEmployeeVendorConfiguration...

CustomerEmployeeVendorQueryDSL...

CustomerEmployeeVendorConnectionQBQL...

Barebones Intuit DefinitionsPublic API for Consumers

Mapping, additional functionality, Intuit

fixes

Page 70: Sand Piles and Software - Madison Ruby Conference

Boundaries example (Web App, generic)

ApplicationDelivery

Domain

Domain Services

Infrastructure

ORM

Application Services

Page 71: Sand Piles and Software - Madison Ruby Conference

Request comes in to find an Order

ApplicationDelivery

Domain

Domain Services

Infrastructure

ORM

Application Services

Page 72: Sand Piles and Software - Madison Ruby Conference

Request comes into to process batch of orders

ApplicationDelivery

Domain

Domain Services

Infrastructure

ORM

Application Services

Page 73: Sand Piles and Software - Madison Ruby Conference

Request comes into to process batch of orders, then notifies customer who placed order.

ApplicationDelivery

Domain

Domain Services

Infrastructure

ORM

Application Services

Page 74: Sand Piles and Software - Madison Ruby Conference

- Classes are great for representing entities and things which have instances (Well-Grounded Rubyist)

- Mixins are great for characteristics or properties of entities, cross-cutting concerns, explicit grouping of functionality

- Composition is a often under-used. You create a new class/object and pass in an existing one as a collaborator/dependency.

Classes, Mixins, Inheritance, and Composition

Page 75: Sand Piles and Software - Madison Ruby Conference

Composition

- full control over your object and API

- reduces the ripple effects of change if the API of the object you’re composing changes

- removes dependencies on parent objects you may or may not own

- simplifies testing because you own it and its dependencies

Page 76: Sand Piles and Software - Madison Ruby Conference

- Give yourself time to reflect

- Personal growth

- Make mid-course corrections

- Keep complexity down

- if you’re only focused on add, add, add, then you don’t give yourself time to do that

Reflection

Page 77: Sand Piles and Software - Madison Ruby Conference

ValuesP r a c t i c e s

over

Page 78: Sand Piles and Software - Madison Ruby Conference

If you actively seek ways to exploit your values, practices will

come naturally.

Page 79: Sand Piles and Software - Madison Ruby Conference

good bad

<insert here>

Page 80: Sand Piles and Software - Madison Ruby Conference

Practices change more oftenthan values.

Page 81: Sand Piles and Software - Madison Ruby Conference

The Vicious Stop n Go.

More effort initially.

critical point

Functionality

Com

plex

ity

Page 82: Sand Piles and Software - Madison Ruby Conference

May the landscape of your software be smooth rolling hills.

twitter: @zachdennis github: zdennis mutuallyhuman.com Sand Piles & Software

Articlein April PragPub