Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Working With Legacy Rails Apps

Working With Legacy Rails Apps

Ahmed Omran

July 10, 2015
Tweet

More Decks by Ahmed Omran

Other Decks in Programming

Transcript

  1. Working With Legacy
    Rails Apps
    @this_ahmed

    View Slide

  2. Working With Legacy
    Rails Apps
    @this_ahmed

    View Slide

  3. 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

    View Slide

  4. googling legacy code …

    View Slide

  5. every project has
    legacy code?

    View Slide

  6. View Slide

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

    View Slide

  8. View Slide

  9. –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.”

    View Slide

  10. in the face of legacy
    code you can …

    View Slide

  11. View Slide

  12. or…

    View Slide

  13. View Slide

  14. Useful techniques

    View Slide

  15. Rebuild Refactor

    View Slide

  16. –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.”

    View Slide

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

    View Slide

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

    View Slide

  19. use mock objects to
    break dependencies

    View Slide

  20. View Slide

  21. mock dependencies

    View Slide

  22. break complicated
    dependencies with
    seams

    View Slide

  23. View Slide

  24. seam => put in method + stub

    View Slide

  25. first step to later
    refactor

    View Slide

  26. i don’t understand this
    code…

    View Slide

  27. Ask someone

    View Slide

  28. code archeology

    View Slide

  29. code archeology
    git blame / Github

    View Slide

  30. code archeology
    search code
    for context
    git blame / Github

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  34. some parting thoughts

    View Slide

  35. unit test

    View Slide

  36. View Slide

  37. View Slide

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

    View Slide