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

Experimental Refactoring with Go

Experimental Refactoring with Go

Refactoring is essential to the software lifecycle. Can we make it safe enough to be a part of every company's CD workflow? In this talk attendees will learn how to: utilise multi-step deploys; tame feature flags; run multiple code paths concurrently in production without influencing users.

Jelmer Snoeck

August 03, 2018
Tweet

More Decks by Jelmer Snoeck

Other Decks in Programming

Transcript

  1. Experimental Refactoring

    View Slide

  2. FIND ME
    github.com/jelmersnoeck
    twitter.com/jelmersnoeck
    Jelmer Snoeck
    ABOUT ME
    - Tech Lead at manifold.co
    - Kubernetes
    - Terraform
    - Gopher since 2013
    - Kubelist Contributor

    View Slide

  3. $ tree
    - What and why?
    - Techniques & Tools
    - Zero Downtime Refactoring
    - Experimental Refactoring

    View Slide

  4. Photo by Dan Gold on Unsplash
    Refactoring

    View Slide

  5. Code refactoring is the process of
    restructuring existing computer code
    without changing its external behavior.
    Wikipedia

    View Slide

  6. Refactoring is a controlled technique for
    improving the design of an existing code
    base.
    Martin Fowler

    View Slide

  7. Refactoring is changing things, deploying
    it and hoping it didn’t break anything
    else.
    Most Developers

    View Slide

  8. Photo by Emily Morter on Unsplash
    Why

    View Slide

  9. Photo by Alfons Morales on Unsplash
    Readability

    View Slide

  10. Photo by Anton Darius on Unsplash
    Code smells

    View Slide

  11. Code smells
    - Duplication
    - Feature envy
    - Large methods
    - Dead code
    - …

    View Slide

  12. Photo by Glen Carrie on Unsplash
    Bugs

    View Slide

  13. Product Changes
    Photo by Chris Lawton on Unsplash
    Product changes

    View Slide

  14. Product changes
    - New features
    - Modify existing features
    - …

    View Slide

  15. Photo by Nainoa Shizuru on Unsplash
    Performance + scalability

    View Slide

  16. Performance
    - Change of underlying package
    - Change of underlying algorithm
    - …

    View Slide

  17. Scalability
    - Userbase growth (100 users to 100m users)
    - Team growth (10 developers to 500 developers)
    - …

    View Slide

  18. Photo by Anoir Chafik on Unsplash

    View Slide

  19. Techniques
    Photo by Uriel Soberanes on Unsplash

    View Slide

  20. Techniques
    - Interface Abstraction
    - Type Aliasing (Go 1.9+)
    - Nil Objects
    - …

    View Slide

  21. Interfaces
    (Abstraction)
    Photo by Rene Böhmer on Unsplash

    View Slide

  22. View Slide

  23. View Slide

  24. View Slide

  25. View Slide

  26. View Slide

  27. Photo by Kipras Štreimikis on Unsplash
    Type Aliasing

    View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. View Slide

  33. Photo by Aaron Burden on Unsplash
    Nil Objects

    View Slide

  34. View Slide

  35. View Slide

  36. View Slide

  37. View Slide

  38. View Slide

  39. View Slide

  40. View Slide

  41. Photo by Philip Swinburn on Unsplash
    Tools

    View Slide

  42. Detection Tools
    - CodeCov
    - Linting
    - …

    View Slide

  43. CodeCov
    Photo by Samuel Zeller on Unsplash

    View Slide

  44. View Slide

  45. View Slide

  46. View Slide

  47. View Slide

  48. View Slide

  49. Linting
    Photo by Terri Bleeker on Unsplash

    View Slide

  50. View Slide

  51. View Slide

  52. View Slide

  53. Refactoring Tools
    - Tests
    - Security that it still works
    - Gotests
    - Benchmarks
    - go test -bench=.
    - IDE
    - Extract methods
    - Find duplication easily

    View Slide

  54. gotests
    Photo by rawpixel on Unsplash

    View Slide

  55. View Slide

  56. View Slide

  57. View Slide

  58. View Slide

  59. go test -bench=.
    Photo by Ashley Baxter on Unsplash

    View Slide

  60. View Slide

  61. View Slide

  62. View Slide

  63. View Slide

  64. Photo by Mark Hessling on Unsplash

    View Slide

  65. Photo by Jyotirmoy Gupta on Unsplash

    View Slide

  66. Photo by Marcus Benedix on Unsplash

    View Slide

  67. Zero
    Downtime
    Refactoring
    Photo by Masaaki Komori on Unsplash

    View Slide

  68. Multi Step Changes
    Photo by Jake Hills on Unsplash

    View Slide

  69. View Slide

  70. View Slide

  71. View Slide

  72. View Slide

  73. View Slide

  74. View Slide

  75. View Slide

  76. Photo by Jane Carmona on Unsplash
    Feature Flags

    View Slide

  77. View Slide

  78. Why use Feature Toggles?
    - Early Access to Features
    - Incremental roll outs to test hypothesis
    - Calendar Events (Mother’s day, Launches, …)
    - …

    View Slide

  79. View Slide

  80. View Slide

  81. View Slide

  82. Metrics
    Photo by Carlos Muza on Unsplash

    View Slide

  83. View Slide

  84. Experimental Refactoring
    Photo by chuttersnap on Unsplash

    View Slide

  85. View Slide

  86. View Slide

  87. Photo by chuttersnap on Unsplash

    View Slide

  88. View Slide

  89. View Slide

  90. View Slide

  91. View Slide

  92. View Slide

  93. View Slide

  94. View Slide

  95. View Slide

  96. View Slide

  97. View Slide

  98. View Slide

  99. View Slide

  100. View Slide

  101. View Slide

  102. @jelmersnoeck
    manifold.co
    Thanks!

    View Slide

  103. Reading list
    - https://speakerdeck.com/campoy/understanding-nil
    - https://talks.golang.org/2016/refactor.article
    - https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go
    - https://github.com/cweill/gotests
    - https://github.com/github/scientist
    - https://github.com/jelmersnoeck/experiment
    - http://featureflags.io/
    - https://github.com/launchdarkly/go-client
    - https://github.com/checkr/flagr

    View Slide