Slide 1

Slide 1 text

Conscious Coding Practice The Three Concrete Steps There's a slide link later. You don't need to write frantically. @codefolio

Slide 2

Slide 2 text

Who's This Guy? I wrote the book "Rebuilding Rails."
 Also a lot about Ruby performance for engineering.appfolio.com. I've been a pro coder for over 20 years. But if you have to care about me to understand this, I did it wrong. And I give out chalk-bear stickers! Ask me after the talk.

Slide 3

Slide 3 text

You want to get better at coding. Faster.

Slide 4

Slide 4 text

The Dragon in the Room: "The Computer Science Stuff"

Slide 5

Slide 5 text

Coding is Practical

Slide 6

Slide 6 text

Good Practice
 is Better than
 Bad Practice (There's a whole "mindful practice" thing you can find in books. Practicing well is a whole field of study.)

Slide 7

Slide 7 text

"Fingertip Feel"

Slide 8

Slide 8 text

Coding Exercises are... Okay. • Somebody experienced has to write them • Don't usually exercise your judgement about what to build • Hard to learn things you don't know • Have to find new ones constantly

Slide 9

Slide 9 text

A Better Choice: The Coding Study I'll tell you where I stole this technique later. It's really good. You pick three things: a Tool, a Task and a Purpose. You do it for yourself (or pairing.) And it's useful for beginners through twenty-year veterans.

Slide 10

Slide 10 text

The Coding Study, In Simple Steps 1. Choose and write your Tool, Task and Purpose 2. Choose how long to work on it 3. Do the work until done, or until time runs out 4. Look back: what went well or poorly?

Slide 11

Slide 11 text

Definitions: Tool, Task, Purpose

Slide 12

Slide 12 text

Tool: Your Language, Libraries, and So On

Slide 13

Slide 13 text

Task: What You Build

Slide 14

Slide 14 text

Purpose: Why You're Building

Slide 15

Slide 15 text

Choosing Your Tool is Easy

Slide 16

Slide 16 text

Two Ways to Choose Task

Slide 17

Slide 17 text

Choose a Task: Easy Way Pick something simple. Pick something you've done before, or a simple exercise from online. Mostly, this method is... fine.

Slide 18

Slide 18 text

Choose a Task: Fun Way Observe the world. Pick something, anything. Turn it into a system of behaviour. (Yes, there will be an example.)

Slide 19

Slide 19 text

How to Choose Your Purpose
 (unless you have one already)

Slide 20

Slide 20 text

Method 1: What Superpower Do You Wish You Had?

Slide 21

Slide 21 text

Method 2: What Decision Scares You?

Slide 22

Slide 22 text

M ethod 3: W hat's the W eirdest Thing that M ight Possibly W ork?

Slide 23

Slide 23 text

An Example Coding Study: The Merry-Go-Round

Slide 24

Slide 24 text

Tool: simple Ruby Task: a tiny simulation of kids on a Merry-Go-Round Purpose: play with that behaviour (age, strength and pushing) to understand it better Timebox: 1 hour (for me, then)

Slide 25

Slide 25 text

# First half kids = [15, 12, 11, 5, 4, 3] kids = kids.map { |age| { age: age, push: 3 * (age - 3), weight: 5 * Math.sqrt(age), cling: 4 * (age - 2), } }

Slide 26

Slide 26 text

# Second half speed = 0 loop do oomph = kids.map { |k| k[:push] }.sum weight = kids.map { |k| k[:weight] }.sum speed += oomph.to_f / weight puts "o: #{oomph}, w: #{weight}, s: #{speed}" if speed > kids[-1][:cling] kids.pop if kids.size == 0 break end end end

Slide 27

Slide 27 text

# Second half (expanded a bit) speed = 0 loop do oomph = kids.map { |k| k[:push] }.sum weight = kids.map { |k| k[:weight] }.sum speed += oomph.to_f / weight if speed > kids[-1][:cling] puts "#{kids.size} little monkeys," + " on the merry-go-round..." puts "#{kids[-1][:age]} fell off and bumped his head" kids.pop if kids.size == 0 puts "No more monkeys on the merry-go-round!" break end end end

Slide 28

Slide 28 text

Different Purpose,
 Different Results (A partial example)

Slide 29

Slide 29 text

Tool: simple Ruby Task: a tiny simulation of kids on a Merry-Go-Round Purpose: Object-Oriented Design

Slide 30

Slide 30 text

class Kid attr_reader :push, :weight, :cling def initialize(age) @age = age @weight = 5 * Math.sqrt(age) @push = 3 * (age - 3) @cling = 4 * (age - 2) end end class MerryGoRound def initialize(kids) # ...and so on

Slide 31

Slide 31 text

Seven Guidelines (But no rules!) Oh? And what if I break them?

Slide 32

Slide 32 text

1: Choose First and Write That is: Choose your Tool, Task and Purpose first, before you begin coding. Write them out, in words. If broken: feature creep.

Slide 33

Slide 33 text

2: Time Limit Choose a time limit. If you're not done by then, stop. If broken: long failures where you don't learn much and long 'successes' where you keep building but stop learning.

Slide 34

Slide 34 text

3: Throw It Away When you've finished the exercise, don't use it for anything else. You're not producing a finished product. If broken: over-engineered prototypes that teach you less and take longer to produce; you start building to use, not to learn.

Slide 35

Slide 35 text

4: One Idea at Once Your Purpose is the idea you're studying. You want it to be one idea big, no more. If broken: your studies take much longer to get started; feature creep; hard to finish.

Slide 36

Slide 36 text

5: Simple, with Layers Start your code very simply and build up in layers. Debug statements help, too. Since you're doing development from scratch on each study, get the benefits of starting from scratch. If broken: long startup for each study; dread of starting; less writing, more debugging.

Slide 37

Slide 37 text

6: Work from Life Look at a real system in the real world. Staring at real complexity and letting it surprise you is the hidden purpose here. If broken: you only refine what you already know instead of learning something nobody (yet) knows; you lose your best cheat.

Slide 38

Slide 38 text

7: Break Rules Nothing is set in stone here. Break all these rules when it makes sense. Or just to see what happens! (Or un-break!) This is play, not work. Break every rule that gets in the way of learning. Or playing!

Slide 39

Slide 39 text

The Fun Way (Again)

Slide 40

Slide 40 text

Pair Coding Studies

Slide 41

Slide 41 text

Pair on defining the task and purpose, not just writing the code Start "flat-footed," don't bring in a fully-developed idea Brainstorm together before typing One person on the keyboard at once Do something small; then swap roles and continue or restart

Slide 42

Slide 42 text

Where I Stole This Who else has too many tools, and must learn by practice? Artists. They call this a "life study." They choose their tasks from life -- drawing people, landscapes, fruit, etc. They have many purposes -- colour studies, composition studies, shading studies... I explain differently for the coding crowd, but only a little.

Slide 43

Slide 43 text

Where Next? @codefolio Slides: https://bit.ly/rubyconf2019-gibbs Ask me in person for chalk teddy bear stickers! You can find more blog posts about this at https://codefol.io and an in-process book at software-technique.com.

Slide 44

Slide 44 text

Questions? @codefolio Slides: https://bit.ly/rubyconf2019-gibbs Ask me in person for chalk teddy bear stickers!