Slide 1

Slide 1 text

Being for the Benefit of Future Developer

Slide 2

Slide 2 text

tx.pignata.com @jpignata

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Launched: May, 2010 1.6 Billion Messages Delivered Monthly Acquired by Skype: August, 2011

Slide 6

Slide 6 text

45 Main Street 20 Jay Street

Slide 7

Slide 7 text

a successful software project will likely be passed down to many different developers in its lifetime

Slide 8

Slide 8 text

we’re a link in the chain

Slide 9

Slide 9 text

our work will outlast our involvement

Slide 10

Slide 10 text

our decisions will be inherited

Slide 11

Slide 11 text

our decisions will be inherited laziness misunderstandings inconsistencies inattentiveness shortcuts procrastination sloppiness dirty laundry

Slide 12

Slide 12 text

legacy code

Slide 13

Slide 13 text

legacy code

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

(ϊಠӹಠ)ϊኯᵲᴸᵲ

Slide 16

Slide 16 text

(ϊಠӹಠ)ϊኯ OMFG.

Slide 17

Slide 17 text

(ϊಠӹಠ)ϊኯ BIG REWRITE!

Slide 18

Slide 18 text

how can we work toward a better future?

Slide 19

Slide 19 text

we’re in the best possible position to e m p a t h i z e w i t h future developer

Slide 20

Slide 20 text

we can anticipate their needs

Slide 21

Slide 21 text

our codebase is an organism

Slide 22

Slide 22 text

nature and nurture

Slide 23

Slide 23 text

every contribution to our project in part defines its genetics

Slide 24

Slide 24 text

the artifacts we leave behind signal to future contributors how to best build upon them

Slide 25

Slide 25 text

Refactor toward Consistency Prune Dead Code Polish Your Interfaces Write Documentation

Slide 26

Slide 26 text

Refactor toward Consistency

Slide 27

Slide 27 text

what is technical debt?

Slide 28

Slide 28 text

learnings not yet reflected in the codebase

Slide 29

Slide 29 text

technical debt is desirable

Slide 30

Slide 30 text

it means we’re shipping our code to the real-world to learn more about it

Slide 31

Slide 31 text

what the technical debt metaphor isn’t

Slide 32

Slide 32 text

it’s not a loophole

Slide 33

Slide 33 text

it’s not a license to do our jobs poorly by writing a check against future productivity

Slide 34

Slide 34 text

we do the best we can with the information we have

Slide 35

Slide 35 text

“A developer's obligation is to make sure that the code as written makes the clearest possible statement as to how the solution was understood at the time of writing.” — Ward Cunningham http://c2.com/cgi/wiki?TechnicalDebt

Slide 36

Slide 36 text

but we’ll learn more

Slide 37

Slide 37 text

our understanding will evolve

Slide 38

Slide 38 text

technical debt is the gap between what we thought and what we now know

Slide 39

Slide 39 text

these learnings must be accumulated and reflected in our codebase

Slide 40

Slide 40 text

what kinds of learnings?

Slide 41

Slide 41 text

domain model

Slide 42

Slide 42 text

design patterns

Slide 43

Slide 43 text

conventions

Slide 44

Slide 44 text

tooling

Slide 45

Slide 45 text

invoking ‘technical debt’ doesn’t allow us to cut corners

Slide 46

Slide 46 text

this isn’t a moral or ethical argument

Slide 47

Slide 47 text

rather it’s a statement about the nature of software

Slide 48

Slide 48 text

cutting corners isn’t simply a disservice to the future

Slide 49

Slide 49 text

more importantly it’s a disservice to the present

Slide 50

Slide 50 text

tense deploys

Slide 51

Slide 51 text

hot fixes

Slide 52

Slide 52 text

resistence to change

Slide 53

Slide 53 text

you’ll feel the pain immediately

Slide 54

Slide 54 text

technical debt is more subtle

Slide 55

Slide 55 text

if we don’t pay the debt, the interest payments will overtake progress

Slide 56

Slide 56 text

we won’t be able to ship

Slide 57

Slide 57 text

REFACTOR REFACTOR REFACTOR

Slide 58

Slide 58 text

remodel aspects of the domain that we now know more precisely

Slide 59

Slide 59 text

ensure consistency in domain concept naming

Slide 60

Slide 60 text

graduate patterns and conventions into standards

Slide 61

Slide 61 text

standardize on tools and approaches

Slide 62

Slide 62 text

refactorings are retcons for your codebase

Slide 63

Slide 63 text

not perfectionist wankery

Slide 64

Slide 64 text

if you could go back in time, how would you build it?

Slide 65

Slide 65 text

refactor and pretend you knew the right way all along

Slide 66

Slide 66 text

consistency will h e l p f u t u r e developer

Slide 67

Slide 67 text

conventions help clarify how to add new features to a system

Slide 68

Slide 68 text

conventions hint where to look when troubleshooting an aspect of the system

Slide 69

Slide 69 text

experiment liberally, ship often, and learn

Slide 70

Slide 70 text

take those learnings and refactor the system

Slide 71

Slide 71 text

don’t tolerate bad neighborhoods

Slide 72

Slide 72 text

the interest payments are valuable feedback

Slide 73

Slide 73 text

Prune Dead Code

Slide 74

Slide 74 text

dead code is a parasitic barnacle on your codebase

Slide 75

Slide 75 text

it provides no business value

Slide 76

Slide 76 text

it creates mental overhead

Slide 77

Slide 77 text

it is noise in a system down emergency

Slide 78

Slide 78 text

it slows down your test suite

Slide 79

Slide 79 text

yet you carry it around like a boat anchor

Slide 80

Slide 80 text

the “turn it back on” fallacy

Slide 81

Slide 81 text

misconception that a dead feature can be trivially re- enabled

Slide 82

Slide 82 text

unfortunately, dead code erodes quickly

Slide 83

Slide 83 text

turning it back on will involve more than flicking a switch

Slide 84

Slide 84 text

some amount of work will be required

Slide 85

Slide 85 text

it’s not free

Slide 86

Slide 86 text

neither is carrying around the defunct implementation

Slide 87

Slide 87 text

this is the sunk cost fallacy in action

Slide 88

Slide 88 text

the “may need it later” false dilemma

Slide 89

Slide 89 text

var article = CMS.retrieve(articleId); //if (article.state === PUBLISHED) { article.render($ele); //}

Slide 90

Slide 90 text

var article = CMS.retrieve(articleId); if (false) article.render($ele);

Slide 91

Slide 91 text

is this a remnant from a debugging session?

Slide 92

Slide 92 text

is it a hint of a future requirement?

Slide 93

Slide 93 text

is it a warning about a possible bug?

Slide 94

Slide 94 text

..****......*...........****.................*..**. *.........***......*..........*...*............**.. ......*......** Finished in 2.62 seconds 117 examples, 0 failures, 24 pending

Slide 95

Slide 95 text

they’d be providing more value as red tests

Slide 96

Slide 96 text

there’s no context provided

Slide 97

Slide 97 text

entangled concerns

Slide 98

Slide 98 text

brittleness sometimes discourages us from good hygiene

Slide 99

Slide 99 text

“I removed the old header styles and now nobody can log in.”

Slide 100

Slide 100 text

“if it ain’t broke, don’t fix it”

Slide 101

Slide 101 text

large swathes of dead code is broke

Slide 102

Slide 102 text

your codebase must communicate clearly

Slide 103

Slide 103 text

that’s its most important job

Slide 104

Slide 104 text

a mix of “real” and “old” code does not communicate clearly

Slide 105

Slide 105 text

understanding these parts will require software archaeology

Slide 106

Slide 106 text

every line of code should be signal

Slide 107

Slide 107 text

extricate the productive parts of your system from the cruft

Slide 108

Slide 108 text

use this as an opportunity to fortify brittle components in your system

Slide 109

Slide 109 text

de-cluttering will help future developer

Slide 110

Slide 110 text

r e d u c e y o u r codebase to its minimum

Slide 111

Slide 111 text

to amplify what it communicates

Slide 112

Slide 112 text

DEAD CODE DELETE

Slide 113

Slide 113 text

relax! it’ll be in source control

Slide 114

Slide 114 text

in case you’re feeling nostalgic

Slide 115

Slide 115 text

Polish Your Interfaces

Slide 116

Slide 116 text

a restaurant kitchen has many responsibilities

Slide 117

Slide 117 text

sourcing ingredients

Slide 118

Slide 118 text

preparing meals

Slide 119

Slide 119 text

table service

Slide 120

Slide 120 text

sanitation

Slide 121

Slide 121 text

we don’t need to anything about how or what the kitchen does

Slide 122

Slide 122 text

the menu is our interface to the kitchen

Slide 123

Slide 123 text

“lol, I dunno.”

Slide 124

Slide 124 text

“check the kitchen, I’m sure you can find some food back there.”

Slide 125

Slide 125 text

that’s what every shapeless component says to future developer

Slide 126

Slide 126 text

comprehension

Slide 127

Slide 127 text

we describe our systems macroscopically by their interactions

Slide 128

Slide 128 text

Web Transport Google Apple Windows PostgreSQL memcached Stripe Sendgrid

Slide 129

Slide 129 text

put it under the microscope and magnify

Slide 130

Slide 130 text

method junk drawers

Slide 131

Slide 131 text

User

Slide 132

Slide 132 text

bad fences, bad neighbors

Slide 133

Slide 133 text

User Payment Sale Processor

Slide 134

Slide 134 text

User Payment Sale Processor #have_credit_card? #card_valid?(card_number) #bill(sale) #user_details) #address .last_payment_for(user) #account_number #renew!(user) #elapsed? #active?

Slide 135

Slide 135 text

murky interfaces

Slide 136

Slide 136 text

“private? whatever. we’re all adults.”

Slide 137

Slide 137 text

method visibility helps us reduce the surface area of an object

Slide 138

Slide 138 text

less surface area means we can change the innards of an object with less fear

Slide 139

Slide 139 text

having a small, well-defined public interface communicates what it does

Slide 140

Slide 140 text

and how it’s supposed to be used

Slide 141

Slide 141 text

o u r s y s t e m s a r e defined by their interactions

Slide 142

Slide 142 text

t h e s h a r p e r a c o m p o n e n t ’ s interface, the clearer your intent

Slide 143

Slide 143 text

extensibility

Slide 144

Slide 144 text

class Cache def initialize(storage) @storage = storage end def fetch(key) get(key) || set(key, yield) end private def get(key) @storage.get(key) end def set(key, data) @storage.set(key, data) data end end

Slide 145

Slide 145 text

>> cache = Cache.new(Redis.new) => #> >> cache.fetch(“key”) { some_expensive_operation } => :some_expensive_operation_result

Slide 146

Slide 146 text

class Cache def initialize(storage) @storage = storage end def fetch(key) get(key) || set(key, yield) end private def get(key) @storage.get(key) end def set(key, data) @storage.set(key, data) data end end

Slide 147

Slide 147 text

wire it up at runtime with a storage backend that responds to #get and #set

Slide 148

Slide 148 text

cache = Cache.new(memcache)

Slide 149

Slide 149 text

cache = Cache.new(redis)

Slide 150

Slide 150 text

cache = Cache.new(CustomCacheBackend.new)

Slide 151

Slide 151 text

redis = Redis::Distributed.new(ENV[“REDIS_URLS”]) cache = Cache.new(redis)

Slide 152

Slide 152 text

naming a concept helps us reason about it

Slide 153

Slide 153 text

Cache represents a conceptual border

Slide 154

Slide 154 text

code reuse

Slide 155

Slide 155 text

we can’t predict future needs accurately

Slide 156

Slide 156 text

speculative generality

Slide 157

Slide 157 text

reuse in the small vs. reuse in the large

Slide 158

Slide 158 text

build components that can be easily reasoned about

Slide 159

Slide 159 text

apply a little design

Slide 160

Slide 160 text

clarity, extensibility, and reuse will follow

Slide 161

Slide 161 text

Write Documentation

Slide 162

Slide 162 text

RTFM

Slide 163

Slide 163 text

RTFM

Slide 164

Slide 164 text

WTFM

Slide 165

Slide 165 text

WTF

Slide 166

Slide 166 text

we demand it from our open source projects

Slide 167

Slide 167 text

but we have different standards for our projects

Slide 168

Slide 168 text

oral tradition and lore

Slide 169

Slide 169 text

graveyard wikis

Slide 170

Slide 170 text

comments

Slide 171

Slide 171 text

comments are lies waiting to be told to the future

Slide 172

Slide 172 text

# Return a NullUser if not logged in return true if logged_in?

Slide 173

Slide 173 text

inline documentation

Slide 174

Slide 174 text

No content

Slide 175

Slide 175 text

No content

Slide 176

Slide 176 text

No content

Slide 177

Slide 177 text

documentation is exposition

Slide 178

Slide 178 text

commit messages

Slide 179

Slide 179 text

your commit messages comprise your project’s changelog

Slide 180

Slide 180 text

breadcrumbs of context for the future

Slide 181

Slide 181 text

git blame

Slide 182

Slide 182 text

$ git commit -am “fixes some stuff”

Slide 183

Slide 183 text

$ git commit -am “Decompose RequestLogger The request logger middleware was responsible for mainipulating HTTP response headers for New Relic logging, sending measurement probes to StatsD, and outputting debugging information about a random sample of requests to the application log. This change splits up its responsibilities into three components: NewRelicHeader, StatsdTimer, DebugLogWriter. * Added coverage for middleware components * Minor consistency fixes in application config

Slide 184

Slide 184 text

$ git rebase -i origin/master reword 0a8a3f6 Only sample for production pick d3d0250 Pass X-Proxy-Start as milliseconds squash 331c23f wip squash 1ee49de checkpoint: green reword b89e605 wip raise timeout if DB unavailable squash b2ed91f Speed up populate task pick db84969 Populate in a downtime migration # Rebase af190fb..10c3493 onto af190fb

Slide 185

Slide 185 text

leave behind a coherent paper trail

Slide 186

Slide 186 text

compare your projects to the standards to which you hold open source software

Slide 187

Slide 187 text

TL;DR

Slide 188

Slide 188 text

fight software entropy

Slide 189

Slide 189 text

fix broken windows

Slide 190

Slide 190 text

work toward consistency

Slide 191

Slide 191 text

leave behind what you hope to find

Slide 192

Slide 192 text

build a better tomorrow for future developer

Slide 193

Slide 193 text

and a better today for yourself

Slide 194

Slide 194 text

Thanks! @jpignata tx.pignata.com

Slide 195

Slide 195 text

Sup? @jpignata tx.pignata.com