Slide 1

Slide 1 text

Inside 30days Album Fighting against legacy code @kyanny #sprk2012 12೥9݄17೔݄༵೔

Slide 2

Slide 2 text

My bitter story For lonely Railers 12೥9݄17೔݄༵೔

Slide 3

Slide 3 text

•Writing tests against legacy code •Technical debt •Attitude towards legacy code 12೥9݄17೔݄༵೔

Slide 4

Slide 4 text

@kyanny Kensuke Nagae ࢗ਎ˑϒʔϝϥϯ 12೥9݄17೔݄༵೔

Slide 5

Slide 5 text

paperboy&co. 12೥9݄17೔݄༵೔

Slide 6

Slide 6 text

http://sqale.jp 12೥9݄17೔݄༵೔

Slide 7

Slide 7 text

http://30d.jp 12೥9݄17೔݄༵೔

Slide 8

Slide 8 text

turn profitable 12೥9݄17೔݄༵೔

Slide 9

Slide 9 text

$ rails -v 12೥9݄17೔݄༵೔

Slide 10

Slide 10 text

2.0.2 ~ June 2012 12೥9݄17೔݄༵೔

Slide 11

Slide 11 text

ଔ ۀ ੜ 12೥9݄17೔݄༵೔

Slide 12

Slide 12 text

2.1.2 Jul 2012 ~ 12೥9݄17೔݄༵೔

Slide 13

Slide 13 text

2008/04 ~ 2012/06 12೥9݄17೔݄༵೔

Slide 14

Slide 14 text

Why need 4 years? 12೥9݄17೔݄༵೔

Slide 15

Slide 15 text

Lack of tests 12೥9݄17೔݄༵೔

Slide 16

Slide 16 text

Need more tests, but... 12೥9݄17೔݄༵೔

Slide 17

Slide 17 text

Writing tests against legacy code is difficult 12೥9݄17೔݄༵೔

Slide 18

Slide 18 text

TDD is idealistic :( 12೥9݄17೔݄༵೔

Slide 19

Slide 19 text

Stub & Mock is your friend :) 12೥9݄17೔݄༵೔

Slide 20

Slide 20 text

Stub def pay! if credit_card.valid? # validate with complex process Payment.create! end end credit_card.stub(:valid?).and_return(true) expects { pay! }.change { Payment.count }.by(1) 12೥9݄17೔݄༵೔

Slide 21

Slide 21 text

Mock def photo.rotate(angle) rpc.call('rotatePhoto', angle) end rpc.should_receive(:call).with('rotatePhoto', 180) photo.rotate(180) 12೥9݄17೔݄༵೔

Slide 22

Slide 22 text

Great weapon for fighting legacy code 12೥9݄17೔݄༵೔

Slide 23

Slide 23 text

12೥9݄17೔݄༵೔

Slide 24

Slide 24 text

“I was worried about writing tests against existent code. It seems stupid. Is it worth?” 12೥9݄17೔݄༵೔

Slide 25

Slide 25 text

12೥9݄17೔݄༵೔

Slide 26

Slide 26 text

࢓༷Խςετ Characterization test http://en.wikipedia.org/wiki/Characterization_test 12೥9݄17೔݄༵೔

Slide 27

Slide 27 text

describe (characterize) the actual behaviour 12೥9݄17೔݄༵೔

Slide 28

Slide 28 text

protect existing behaviour 12೥9݄17೔݄༵೔

Slide 29

Slide 29 text

def sleep_sort(ary) ary.map{|n|Thread.new{sleep n; $*<

Slide 30

Slide 30 text

“Don't worry. You're right.” 12೥9݄17೔݄༵೔

Slide 31

Slide 31 text

12೥9݄17೔݄༵೔

Slide 32

Slide 32 text

Technical debt 12೥9݄17೔݄༵೔

Slide 33

Slide 33 text

•Outdated parts •Bad design 12೥9݄17೔݄༵೔

Slide 34

Slide 34 text

BackgrounDRb 12೥9݄17೔݄༵೔

Slide 35

Slide 35 text

“Friends don’t let friends use backgrounDRb.” http://www.engineyard.com/blog/2009/5-tips-for- deploying-background-jobs/ 12೥9݄17೔݄༵೔

Slide 36

Slide 36 text

DelayedJob 12೥9݄17೔݄༵೔

Slide 37

Slide 37 text

DelayedJob Not

Slide 38

Slide 38 text

Monkey patching :P 12೥9݄17೔݄༵೔

Slide 39

Slide 39 text

if Rails::VERSION::STRING <= '2.1.2' unless Time.singleton_methods.include?(:zone) class Time def self.zone Time # enable to call Time.zone.now end end end end 12೥9݄17೔݄༵೔

Slide 40

Slide 40 text

Bad schema 12೥9݄17೔݄༵೔

Slide 41

Slide 41 text

SELECT * FROM photos WHERE album_id = ? AND (deleted_at IS NULL OR deleted_at >= ?) SQL modification by acts_as_paranoid 12೥9݄17೔݄༵೔

Slide 42

Slide 42 text

create_table :photos do |t| t.string :id end Non Integer id (UUID) 12೥9݄17೔݄༵೔

Slide 43

Slide 43 text

Bad schema causes slow queries, but schema change is hard. 12೥9݄17೔݄༵೔

Slide 44

Slide 44 text

Buy high-performance hardware to make up for bad design :) 12೥9݄17೔݄༵೔

Slide 45

Slide 45 text

Long holiday Buy new server & SSD 12೥9݄17೔݄༵೔

Slide 46

Slide 46 text

12೥9݄17೔݄༵೔

Slide 47

Slide 47 text

Attitude towards legacy code 12೥9݄17೔݄༵೔

Slide 48

Slide 48 text

Be realistic as a business person 12೥9݄17೔݄༵೔

Slide 49

Slide 49 text

Don’t stick the ideal 12೥9݄17೔݄༵೔

Slide 50

Slide 50 text

Be proud as a Developer 12೥9݄17೔݄༵೔

Slide 51

Slide 51 text

Aim for perfect code 12೥9݄17೔݄༵೔

Slide 52

Slide 52 text

12೥9݄17೔݄༵೔

Slide 53

Slide 53 text

Don't leave a technical debt to future 12೥9݄17೔݄༵೔

Slide 54

Slide 54 text

Break the negative chain 12೥9݄17೔݄༵೔

Slide 55

Slide 55 text

Conclusion 12೥9݄17೔݄༵೔

Slide 56

Slide 56 text

Writing tests against legacy code is difficult. But it will pay. 12೥9݄17೔݄༵೔

Slide 57

Slide 57 text

Technical debt can make up by money. Save your time. 12೥9݄17೔݄༵೔

Slide 58

Slide 58 text

Break the negative chain 12೥9݄17೔݄༵೔

Slide 59

Slide 59 text

Thank you! 12೥9݄17೔݄༵೔

Slide 60

Slide 60 text

Question? 12೥9݄17೔݄༵೔