Slide 1

Slide 1 text

Broken Windows Alexander Tamoykin http://alextamoykin.com

Slide 2

Slide 2 text

Agenda •What •Why •How

Slide 3

Slide 3 text

What is broken Windows?

Slide 4

Slide 4 text

What What ?

Slide 5

Slide 5 text

Lunch

Slide 6

Slide 6 text

Changed your mind ?

Slide 7

Slide 7 text

Just go with it

Slide 8

Slide 8 text

William Bratton

Slide 9

Slide 9 text

Simplified Code Example class SWE < ActiveRecord::Base! has_many :registrations! ! def go_to_conference! my_registration = registrations.find_by_swe_id id! my_registration.book! end! end

Slide 10

Slide 10 text

How do we get there ? class SWE < ActiveRecord::Base! has_many :flights! has_many :registrations! ! def go_to_conference! my_flight = flights.find_by_swe_id id! my_flight.book! my_registration.book = registrations.find_by_swe_id id! my_registration.book! end! end

Slide 11

Slide 11 text

Where do we stay ? class SWE < ActiveRecord::Base! has_many :flights! has_many :hotels! has_many :registrations! ! def go_to_conference! my_hotel = hotels.find_by_swe_id id! my_hotel.book! my_flight = flights.find_by_swe_id id! my_flight.book! my_registration = registrations.find_by_swe_id id! my_registration.book! end! end

Slide 12

Slide 12 text

What if the conference is sold out ? class SWE < ActiveRecord::Base! has_many :flights! has_many :hotels! has_many :registrations! ! def go_to_conference! my_registration = registrations.find_by_swe_id id! ! if my_registration.book! my_hotel = hotels.find_by_swe_id id! my_hotel.book! my_flight = flights.find_by_swe_id id! my_flight.book! end! end! end

Slide 13

Slide 13 text

What if there is no hotel ? class SWE < ActiveRecord::Base! has_many :flights! has_many :hotels! has_many :registrations! ! def go_to_conference! my_registration = registrations.find_by_swe_id id! if my_registration.book! my_hotel = hotels.find_by_swe_id id! if my_hotel.book! my_flight = flights.find_by_swe_id id! my_flight.book! end! end! end! end

Slide 14

Slide 14 text

Hard to change!

Slide 15

Slide 15 text

Is this easier to change ? class SWE < ActiveRecord::Base! …! def go_to_conference! register! book_hotel! book_flight! end! ! def book_flight! my_flight = flights.find_by_swe_id id! my_flight.book! end! ! def book_hotel! my_hotel = hotels.find_by_swe_id id! my_hotel.book! end! ! def register! my_registration = registrations.find_by_swe_id id! my_registration.book! end! end

Slide 16

Slide 16 text

How did it happen ? class SWE < ActiveRecord::Base! has_many :flights! has_many :hotels! has_many :registrations! ! def go_to_conference! my_registration = registrations.find_by_swe_id id! if my_registration.book! my_hotel = hotels.find_by_swe_id id! if my_hotel.book! my_flight = flights.find_by_swe_id id! my_flight.book! end! end! end! end

Slide 17

Slide 17 text

Human Nature • Survive • Adapt to the environment • Do what everyone else does

Slide 18

Slide 18 text

What’s the problem ? Cost to Change Technical Debt

Slide 19

Slide 19 text

What’s the problem ? Cost to Change Technical Debt

Slide 20

Slide 20 text

Why • Legacy Code • Time Pressure • It can’t be worse

Slide 21

Slide 21 text

Pragmatic Advise

Slide 22

Slide 22 text

How • Identify a broken window • Refactor it • Track it • Come back and do it right • Leave a comment

Slide 23

Slide 23 text

Do it! Before it’s too late

Slide 24

Slide 24 text

Concrete Examples • Write a missing test • Split a large class into smaller classes • Look at Code Climate • Delete dead code • Review a pull request • Take a fresh look tomorrow • Encourage your coworker to fix it • Incrementally refactor

Slide 25

Slide 25 text

Most Importantly

Slide 26

Slide 26 text

The End http://alextamoykin.com