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 full-size 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 full-size slide

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

    View full-size slide

  4. Photo by Dan Gold on Unsplash
    Refactoring

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  8. Photo by Emily Morter on Unsplash
    Why

    View full-size slide

  9. Photo by Alfons Morales on Unsplash
    Readability

    View full-size slide

  10. Photo by Anton Darius on Unsplash
    Code smells

    View full-size slide

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

    View full-size slide

  12. Photo by Glen Carrie on Unsplash
    Bugs

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  15. Photo by Nainoa Shizuru on Unsplash
    Performance + scalability

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  18. Photo by Anoir Chafik on Unsplash

    View full-size slide

  19. Techniques
    Photo by Uriel Soberanes on Unsplash

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  22. Photo by Kipras Štreimikis on Unsplash
    Type Aliasing

    View full-size slide

  23. Photo by Aaron Burden on Unsplash
    Nil Objects

    View full-size slide

  24. Photo by Philip Swinburn on Unsplash
    Tools

    View full-size slide

  25. Detection Tools
    - CodeCov
    - Linting
    - …

    View full-size slide

  26. CodeCov
    Photo by Samuel Zeller on Unsplash

    View full-size slide

  27. Linting
    Photo by Terri Bleeker on Unsplash

    View full-size slide

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

    View full-size slide

  29. gotests
    Photo by rawpixel on Unsplash

    View full-size slide

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

    View full-size slide

  31. Photo by Mark Hessling on Unsplash

    View full-size slide

  32. Photo by Jyotirmoy Gupta on Unsplash

    View full-size slide

  33. Photo by Marcus Benedix on Unsplash

    View full-size slide

  34. Zero
    Downtime
    Refactoring
    Photo by Masaaki Komori on Unsplash

    View full-size slide

  35. Multi Step Changes
    Photo by Jake Hills on Unsplash

    View full-size slide

  36. Photo by Jane Carmona on Unsplash
    Feature Flags

    View full-size slide

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

    View full-size slide

  38. Metrics
    Photo by Carlos Muza on Unsplash

    View full-size slide

  39. Experimental Refactoring
    Photo by chuttersnap on Unsplash

    View full-size slide

  40. Photo by chuttersnap on Unsplash

    View full-size slide

  41. @jelmersnoeck
    manifold.co
    Thanks!

    View full-size slide

  42. 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 full-size slide