Slide 1

Slide 1 text

Working With Legacy Rails Apps @this_ahmed

Slide 2

Slide 2 text

Working With Legacy Rails Apps @this_ahmed

Slide 3

Slide 3 text

legacy code • untested code (Michael C. Feathers) • code someone else wrote (old gems, outsourcing, maintainers left) • difficult to work with • risky to change • but serves a useful function

Slide 4

Slide 4 text

googling legacy code …

Slide 5

Slide 5 text

every project has legacy code?

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

• learning & experimenting • ambitious applications • big project, developer churn, hiring outside help • bad code … even with the best of intentions • “Technical debt”

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

–Robert C. Martin “Even the most disciplined development team, knowing the best principles, using the best patterns, and following the best practices will create messes from time to time.”

Slide 10

Slide 10 text

in the face of legacy code you can …

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

or…

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Useful techniques

Slide 15

Slide 15 text

Rebuild Refactor

Slide 16

Slide 16 text

–Robert C. Martin “…taking a tangled, opaque, convoluted system and slowly, gradually, piece by piece, step by step, turning it into a simple, nicely structured, well-designed system.”

Slide 17

Slide 17 text

Boy Scout Rule Clean up around you work area. Small fixes; small refractors.

Slide 18

Slide 18 text

cover and modify • add unit test • test passes • modify code • test passes

Slide 19

Slide 19 text

use mock objects to break dependencies

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

mock dependencies

Slide 22

Slide 22 text

break complicated dependencies with seams

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

seam => put in method + stub

Slide 25

Slide 25 text

first step to later refactor

Slide 26

Slide 26 text

i don’t understand this code…

Slide 27

Slide 27 text

Ask someone

Slide 28

Slide 28 text

code archeology

Slide 29

Slide 29 text

code archeology git blame / Github

Slide 30

Slide 30 text

code archeology search code for context git blame / Github

Slide 31

Slide 31 text

code archeology project management ticket git blame / Github search code for context

Slide 32

Slide 32 text

code archeology git blame / Github project management ticket commit message search code for context

Slide 33

Slide 33 text

review • boy scout rule • cover and modify • break dependencies with mocks and seams • understand code with archeology

Slide 34

Slide 34 text

some parting thoughts

Slide 35

Slide 35 text

unit test

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

• code review • small git branches • add lots of context in pull request / commit message