Slide 1

Slide 1 text

Stop using development mode. by @tomstuart, at Railsberry, in Kraków, on 2012-04-20.

Slide 2

Slide 2 text

How to develop a Rails application:

Slide 3

Slide 3 text

RAILS_ENV=development

Slide 4

Slide 4 text

config/environments/ development.rb: config.cache_classes = false

Slide 5

Slide 5 text

$ rails server

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

(That was 2005.)

Slide 19

Slide 19 text

Development mode is what first got me excited about Rails.

Slide 20

Slide 20 text

Reload-driven development ™

Slide 21

Slide 21 text

What’s wrong with this methodology?

Slide 22

Slide 22 text

cowboy programming testless programming inside-out programming it encourages:

Slide 23

Slide 23 text

Cowboy programming

Slide 24

Slide 24 text

programming before thinking pressing reload until it looks like it’s working writing the code you want to write

Slide 25

Slide 25 text

Testless programming

Slide 26

Slide 26 text

why write tests when you can press reload?

Slide 27

Slide 27 text

PRESSING RELOAD DOESN’T SCALE

Slide 28

Slide 28 text

why write tests when you can press reload? the app works! now write tests so you don’t feel guilty the app broke! now write tests so it doesn’t break again

Slide 29

Slide 29 text

THE DEFINITION OF WORKING IS THAT THE TESTS PASS

Slide 30

Slide 30 text

Inside-out programming

Slide 31

Slide 31 text

write a migration write a model write a controller write a template write a route press reload

Slide 32

Slide 32 text

database.

Slide 33

Slide 33 text

database. model.

Slide 34

Slide 34 text

database. model. controller.

Slide 35

Slide 35 text

database. model. controller. template.

Slide 36

Slide 36 text

database. model. controller. template. route. user.

Slide 37

Slide 37 text

You build each layer before you’ve built the layer that uses it.

Slide 38

Slide 38 text

You are imagining what the next layer will need this one to do.

Slide 39

Slide 39 text

If you love imagining things that much,

Slide 40

Slide 40 text

move to Los Angeles

Slide 41

Slide 41 text

and become a Scientologist.

Slide 42

Slide 42 text

Development mode doesn’t let you see anything working until you’ve completed a full vertical slice through the application.

Slide 43

Slide 43 text

This makes it easier to write badly designed code.

Slide 44

Slide 44 text

If Rails has a development mode, shouldn’t I use it?

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

What’s a “web framework”?

Slide 47

Slide 47 text

“A collection of libraries, utilities and conventions to make web application development easier.”

Slide 48

Slide 48 text

You are right and good.

Slide 49

Slide 49 text

“A note from my mother excusing me from responsibility for every decision.”

Slide 50

Slide 50 text

YOUR FAULT YOU ARE WRONG AND BAD EVERYTHING IS

Slide 51

Slide 51 text

Rails is software. It doesn’t care about you.

Slide 52

Slide 52 text

Be mindful. Use judgement.

Slide 53

Slide 53 text

There is a better way.

Slide 54

Slide 54 text

Two related ideas:

Slide 55

Slide 55 text

1. Work outside-in.

Slide 56

Slide 56 text

Start by writing an acceptance test to explain the ultimate goal.

Slide 57

Slide 57 text

(An automated one.)

Slide 58

Slide 58 text

Drill down into the application by writing unit tests to set intermediate goals.

Slide 59

Slide 59 text

Make progress towards the ultimate goal by getting unit tests to pass, not by pressing reload.

Slide 60

Slide 60 text

Reach the ultimate goal by getting the acceptance test to pass, not by pressing reload.

Slide 61

Slide 61 text

(During development, your primary clients are automated tests, not web browsers.)

Slide 62

Slide 62 text

How is this possible? How can you test the controller before writing the model?

Slide 63

Slide 63 text

2. Use mocking.

Slide 64

Slide 64 text

Ruby is inspired by Smalltalk.

Slide 65

Slide 65 text

Smalltalk says: a program is a network of collaborating objects.

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Reboot your brain to think in terms of object collaboration.

Slide 68

Slide 68 text

Drive out the design of objects using mocking, not guessing.

Slide 69

Slide 69 text

mock these unit test this

Slide 70

Slide 70 text

You can implement an object before its collaborators exist.

Slide 71

Slide 71 text

By the time you start implementing them, you’ll already know what they need to do.

Slide 72

Slide 72 text

It’s not about coverage, it’s about driving your design directly at every level.

Slide 73

Slide 73 text

The only limitation is your acceptance tests.

Slide 74

Slide 74 text

Some automated tests are too hard, or impossible, to write.

Slide 75

Slide 75 text

Fine: use development mode to run those acceptance tests with your eyes and brain.

Slide 76

Slide 76 text

Why work this way?

Slide 77

Slide 77 text

Better design. Better code. Less pressing reload. Faster tests.

Slide 78

Slide 78 text

It is possible to build a web application without opening a web browser.

Slide 79

Slide 79 text

“Do I need to use development mode?”

Slide 80

Slide 80 text

In practice:

Slide 81

Slide 81 text

growing-object-oriented-software.com

Slide 82

Slide 82 text

pragprog.com/book/achbd/the-rspec-book

Slide 83

Slide 83 text

Thank you. @tomstuart / [email protected] / computationbook.com