Slide 1

Slide 1 text

Writing Empathetic Code - Ruby, Postel’s Law, and a Little Philosophy Joe Mastey

Slide 2

Slide 2 text

What is Empathetic Code, and Why Should We Write it?

Slide 3

Slide 3 text

Code is empathetic if we can confidently and comfortably manipulate it. Most code is not empathetic. This sucks.

Slide 4

Slide 4 text

Readability > (Some) Performance

Slide 5

Slide 5 text

So How Do We Write It?

Slide 6

Slide 6 text

– Jon Postel “Be conservative in what you send, be liberal in what you accept.”

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Coincidence?

Slide 10

Slide 10 text

– Lao Tsu, The Tao Te Ching “The highest virtue is to act without a sense of self The highest kindness is to give without a condition The highest justice is to see without a preference”

Slide 11

Slide 11 text

An Example

Slide 12

Slide 12 text

{{ ORIGINAL CODE }}

Slide 13

Slide 13 text

“Be conservative in what you send”

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Return Types Inputs Output Philosopher, Thought Thought Philosopher, [Thought, …] [Thought, …] Pleb, anything nil

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

“Be liberal in what you accept”

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

{{ WIP WITH ARRAY() PATTERN }}

Slide 22

Slide 22 text

WTF is Kernel#Array()

Slide 23

Slide 23 text

Kernel#Array() Input Output array unmodified object that implements :to_ary object.to_a nil [ ] object [ object ]

Slide 24

Slide 24 text

Other Conversion Functions Complex() Float() Hash() Integer() Rational() String()

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

{{ FINAL PRODUCT WITH USER() CASTING }}

Slide 28

Slide 28 text

So What Do I Win?

Slide 29

Slide 29 text

– Pete Hodgson, “Rails as a SOA Client” “This is the way you evolve (SOA) systems over time without having to redeploy your entire enterprise at once.”

Slide 30

Slide 30 text

More Things to Think About Our tests are also docs, how do we optimize for that? Should we do UX for software libraries? How can we make code that acts as a good role model to the next developer? Good code should reduce the need for documentation (because nobody writes good docs anyway)

Slide 31

Slide 31 text

More Resources Confident Ruby (eBook) - Avdi Grimm Practical Object Oriented Design in Ruby - Sandi Metz Thanks.