Slide 1

Slide 1 text

Kyle Crum - Senior Developer / Team Lead reverb.com twitter: @kylecrum email: [email protected] Communicating Code

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

1. Sellers List Item

Slide 5

Slide 5 text

1. Sellers List Item 2. Buyers Purchase Item

Slide 6

Slide 6 text

1. Sellers List Item 2. Buyers Purchase Item 3. Profit

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

1. Sellers List Item

Slide 9

Slide 9 text

1. Sellers List Item 2….15 Humans being Humans.

Slide 10

Slide 10 text

1. Sellers List Item 2….15 Humans being Humans. 16. Profit

Slide 11

Slide 11 text

Why do I care about communication?

Slide 12

Slide 12 text

Code is for people.

Slide 13

Slide 13 text

People need to understand.

Slide 14

Slide 14 text

Misunderstanding

Slide 15

Slide 15 text

Misunderstanding Bugs

Slide 16

Slide 16 text

Misunderstanding Bugs Less Coding Time

Slide 17

Slide 17 text

Unclear Code = Less Efficiency

Slide 18

Slide 18 text

Even Businesses Agree Moar efficiency = moar good

Slide 19

Slide 19 text

Unclear code

Slide 20

Slide 20 text

Unclear code Sugar?

Slide 21

Slide 21 text

Unclear code Puppy? Sugar?

Slide 22

Slide 22 text

Unclear code Puppy? Sugar?

Slide 23

Slide 23 text

Clear Code

Slide 24

Slide 24 text

Design Principles

Slide 25

Slide 25 text

Design Principles S O L I D

Slide 26

Slide 26 text

Design Principles S O L I D Single Responsibility Open/Closed Liskov Substitution Interface Segregation Dependency Inversion

Slide 27

Slide 27 text

Design Principles S O L I D Single Responsibility Open/Closed Liskov Substitution Interface Segregation Dependency Inversion KISS

Slide 28

Slide 28 text

Design Principles S O L I D Single Responsibility Open/Closed Liskov Substitution Interface Segregation Dependency Inversion KISS DRY

Slide 29

Slide 29 text

Design Principles S O L I D Single Responsibility Open/Closed Liskov Substitution Interface Segregation Dependency Inversion KISS YAGNI DRY

Slide 30

Slide 30 text

KISS my SOLID YAGNI!

Slide 31

Slide 31 text

Just communicate.

Slide 32

Slide 32 text

2 Things to communicate

Slide 33

Slide 33 text

2 Things to communicate 1. What you are doing.

Slide 34

Slide 34 text

2 Things to communicate 1. What you are doing. 2. Why you are doing it.

Slide 35

Slide 35 text

The “What”

Slide 36

Slide 36 text

Ruby can be artistic

Slide 37

Slide 37 text

Ruby can be artistic

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Ruby can be artistic

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Sometimes it’s too much

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

code != art

Slide 44

Slide 44 text

code == a_manual

Slide 45

Slide 45 text

code == a_manual

Slide 46

Slide 46 text

How can we make code more manual-like?

Slide 47

Slide 47 text

Class naming

Slide 48

Slide 48 text

2 kinds of classes

Slide 49

Slide 49 text

2 kinds of classes • Things (models, views, controllers, view models). Has state.

Slide 50

Slide 50 text

2 kinds of classes • Things (models, views, controllers, view models). Has state. • Processes

Slide 51

Slide 51 text

2 kinds of classes • Things (models, views, controllers, view models). Has state. • Processes Easy Naming

Slide 52

Slide 52 text

2 kinds of classes • Things (models, views, controllers, view models). Has state. • Processes Hard Naming Easy Naming

Slide 53

Slide 53 text

When we do the easy thing..

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Refund Part

Slide 56

Slide 56 text

Refund Part Charge Part

Slide 57

Slide 57 text

Refund Part Void Part Charge Part

Slide 58

Slide 58 text

Break into processes instead

Slide 59

Slide 59 text

Naming Process Classes

Slide 60

Slide 60 text

Naming Process Classes 1.

Slide 61

Slide 61 text

Naming Process Classes 1. 2.

Slide 62

Slide 62 text

?

Slide 63

Slide 63 text

? Existential Crisis!

Slide 64

Slide 64 text

?

Slide 65

Slide 65 text

? Is Person?

Slide 66

Slide 66 text

? Is Person? Is Machine?

Slide 67

Slide 67 text

? Is Person? Is Machine? ?

Slide 68

Slide 68 text

What does this say?

Slide 69

Slide 69 text

What does this say? • Has state

Slide 70

Slide 70 text

What does this say? • Has state • Can be passed as argument / variable

Slide 71

Slide 71 text

Is that what I want to say?

Slide 72

Slide 72 text

Probably not.

Slide 73

Slide 73 text

One step away from..

Slide 74

Slide 74 text

One step away from..

Slide 75

Slide 75 text

Instead…

Slide 76

Slide 76 text

Verb “process” classes

Slide 77

Slide 77 text

Easier to spot naming smells

Slide 78

Slide 78 text

Easier to spot naming smells • what does it do?

Slide 79

Slide 79 text

Easier to spot naming smells • what does it do? • what is it executing?

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

• clearly says “what”

Slide 82

Slide 82 text

• clearly says “what” • constrains ability to bloat

Slide 83

Slide 83 text

Still too generic!

Slide 84

Slide 84 text

Still too generic! For all the times?

Slide 85

Slide 85 text

Namespace!

Slide 86

Slide 86 text

Namespace!

Slide 87

Slide 87 text

Namespace! Not lib

Slide 88

Slide 88 text

Namespace! Not lib Used during checkout

Slide 89

Slide 89 text

Namespace!

Slide 90

Slide 90 text

Namespace! The What

Slide 91

Slide 91 text

Namespace! The What The Why

Slide 92

Slide 92 text

Methods

Slide 93

Slide 93 text

Yell at Rails section

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

Is href?

Slide 97

Slide 97 text

Is href? Is href?

Slide 98

Slide 98 text

Is href? Is href? ID of?

Slide 99

Slide 99 text

Let’s time travel!

Slide 100

Slide 100 text

Let’s time travel! …and bring ruby 2.0

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

Is content!

Slide 103

Slide 103 text

Is content! href required!

Slide 104

Slide 104 text

Is content! href required! HTML Attributes!

Slide 105

Slide 105 text

vs.

Slide 106

Slide 106 text

vs.

Slide 107

Slide 107 text

No reason not to use key-value arguments

Slide 108

Slide 108 text

No reason not to use key-value arguments* * Ruby > 2 only

Slide 109

Slide 109 text

Key-value arg all the things!

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

+

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

Things needed

Slide 114

Slide 114 text

Things needed Things I can do

Slide 115

Slide 115 text

All kinds of space!

Slide 116

Slide 116 text

ok?

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

• All code executes

Slide 119

Slide 119 text

• All code executes • Does not add to the understanding.

Slide 120

Slide 120 text

= =

Slide 121

Slide 121 text

= =

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

Too much communication?

Slide 125

Slide 125 text

Probably

Slide 126

Slide 126 text

Probably* * But who cares?

Slide 127

Slide 127 text

More communication > Less communication

Slide 128

Slide 128 text

More clarity > Less clarity

Slide 129

Slide 129 text

Before

Slide 130

Slide 130 text

Before

Slide 131

Slide 131 text

Refund Void Charge Add

Slide 132

Slide 132 text

Inside the methods..

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

No content

Slide 135

Slide 135 text

Read the code out loud

Slide 136

Slide 136 text

No content

Slide 137

Slide 137 text

No content

Slide 138

Slide 138 text

No content

Slide 139

Slide 139 text

No content

Slide 140

Slide 140 text

No content

Slide 141

Slide 141 text

No content

Slide 142

Slide 142 text

No content

Slide 143

Slide 143 text

Code is fun to read again!

Slide 144

Slide 144 text

Let’s talk about meta- programming

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

No content

Slide 147

Slide 147 text

What methods does it have?

Slide 148

Slide 148 text

False Economy

Slide 149

Slide 149 text

False Economy • You saved on typing.

Slide 150

Slide 150 text

False Economy • You saved on typing. • Everyone else spends more time reading/ understanding.

Slide 151

Slide 151 text

No content

Slide 152

Slide 152 text

Methods!

Slide 153

Slide 153 text

Meta programming as salt

Slide 154

Slide 154 text

Just a little

Slide 155

Slide 155 text

Too much…

Slide 156

Slide 156 text

The “Why”

Slide 157

Slide 157 text

Why “The Why”?

Slide 158

Slide 158 text

Why “The Why”? 1. Empathy

Slide 159

Slide 159 text

Why “The Why”? 1. Empathy 2. See #1

Slide 160

Slide 160 text

All Code Starts

Slide 161

Slide 161 text

But becomes…

Slide 162

Slide 162 text

How the did this get here?

Slide 163

Slide 163 text

Commit Messages

Slide 164

Slide 164 text

Bad Commit messages Fix Bug

Slide 165

Slide 165 text

Bad Commit messages Fix Bug What

Slide 166

Slide 166 text

Bad Commit messages Fix Bug What Why?

Slide 167

Slide 167 text

Bad Commit messages Fix Bug What Why?

Slide 168

Slide 168 text

Good Commit Messages

Slide 169

Slide 169 text

Good Commit Messages Handle payments of $0 With a marketing promotion, some buyers are able to buy low-cost, free shipping items for free. - Skip credit card processing when >= $0 - Create a payment for $0 for tracking

Slide 170

Slide 170 text

Good Commit Messages Handle payments of $0 With a marketing promotion, some buyers are able to buy low-cost, free shipping items for free. - Skip credit card processing when >= $0 - Create a payment for $0 for tracking What

Slide 171

Slide 171 text

Good Commit Messages Handle payments of $0 With a marketing promotion, some buyers are able to buy low-cost, free shipping items for free. - Skip credit card processing when >= $0 - Create a payment for $0 for tracking What Why

Slide 172

Slide 172 text

No content

Slide 173

Slide 173 text

Reads Code

Slide 174

Slide 174 text

Reads Code

Slide 175

Slide 175 text

Reads Code git log

Slide 176

Slide 176 text

Reads Code git log

Slide 177

Slide 177 text

You have the space! Use it!

Slide 178

Slide 178 text

Code Comments

Slide 179

Slide 179 text

This seems wrong

Slide 180

Slide 180 text

This seems wrong

Slide 181

Slide 181 text

This seems wrong Ah, ok

Slide 182

Slide 182 text

Bad Comments

Slide 183

Slide 183 text

Bad Comments Same

Slide 184

Slide 184 text

Bad Comments Same Doesn’t help understanding.

Slide 185

Slide 185 text

No content

Slide 186

Slide 186 text

“What happened?”

Slide 187

Slide 187 text

“What happened?” “2 cars hit each other"

Slide 188

Slide 188 text

Good Comments Added info

Slide 189

Slide 189 text

Empathy is important!

Slide 190

Slide 190 text

Empathy is important! Read bad code

Slide 191

Slide 191 text

Empathy is important! Read bad code Knows why it is bad

Slide 192

Slide 192 text

Knowing why = having empathy

Slide 193

Slide 193 text

When we know what and why

Slide 194

Slide 194 text

When we know what and why • Understand the code better.

Slide 195

Slide 195 text

When we know what and why • Understand the code better. • Understand each other better

Slide 196

Slide 196 text

When we know what and why • Understand the code better. • Understand each other better • Happier, more productive team.

Slide 197

Slide 197 text

When we know what and why • Understand the code better. • Understand each other better • Happier, more productive team. • Programming is fun!

Slide 198

Slide 198 text

No content

Slide 199

Slide 199 text

twitter: @kylecrum email: [email protected]