Slide 1

Slide 1 text

REFACTOR O R D I E

Slide 2

Slide 2 text

Sho Kusano @rosylilly Engineer

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers

Slide 5

Slide 5 text

1 http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers Classes can be no longer than one hundred lines of code

Slide 6

Slide 6 text

2 http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers Methods can be no longer than five lines of code

Slide 7

Slide 7 text

3 http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers Pass no more than four parameters into a method. Hash options are parameters.

Slide 8

Slide 8 text

4 http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers Controllers can instantiate only one object. Therefore, views can only know about one instance variable and views should only send messages to that object (@object.collaborator.value is not allowed)

Slide 9

Slide 9 text

0 http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers Sandi Metz’ rules for developers You should break these rules only if you have a good reason or your pair lets you

Slide 10

Slide 10 text

Let’s refactor your codes!

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Where we can start refactoring?

Slide 13

Slide 13 text

rubocop https://github.com/bbatsov/rubocop Save your coding rules

Slide 14

Slide 14 text

$ rubocop ... C:264: Surrounding space missing for '{'. C:264: Surrounding space missing for '{'. C:264: Space missing to the left of '}'. C:282: Line is too long. [98/79] C:283: Line is too long. [81/79] C:284: Method has too many lines. [45/10] C:287: Prefer single-quoted strings when you don't need string interpolation or special symbols. C:288: Line is too long. [115/79] C:298: Indent when as deep as case. C:300: Indent when as deep as case. C:305: Line is too long. [98/79] C:310: Indent when as deep as case. C:318: Indent when as deep as case. C:320: Indent when as deep as case. ...

Slide 15

Slide 15 text

simplecov https://github.com/colszowka/simplecov Don’t end with “FIXME”

Slide 16

Slide 16 text

$ COV=1 rspec spec/models ............................................................... Finished in 1.62 seconds 63 examples, 0 failures Coverage report generated for RSpec to coverage. 140 / 140 LOC (100.0%) covered.

Slide 17

Slide 17 text

Module#deprecate http://api.rubyonrails.org/classes/Module.html#method-i-deprecate Don’t get on the time machine

Slide 18

Slide 18 text

class DirtyModel def old_method # body omitted ... end deprecate :old_method def new_method # body omitted ... end if Rails.env.test? alias_method :old_method, :new_method end end

Slide 19

Slide 19 text

Let’s refactor your codes!

Slide 20

Slide 20 text

WE ARE HIRING !! Let’s refactor our codes together !! http://info.cookpad.com/jobs/?affcd=geo2a

Slide 21

Slide 21 text

One more dish

Slide 22

Slide 22 text

24-hours Hackathon Competition http://info.cookpad.com/24contest4 Twitter: @24contest / Hashtags: #24contest 2013 / 06 / 15 09:00 a.m. ʙ 06 / 16 09:00 a.m.

Slide 23

Slide 23 text

Thank you for listening https://speakerdeck.com/rosylilly/refactor-or-die

Slide 24

Slide 24 text

sora_h my wife Special Thanks