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

Introduce go-mnd

Introduce go-mnd

Short introduction of go-mnd, the magic number detector for Go.

C739f65cecbb38923d95e9b7cc0d2e63?s=128

Tommy Mühle

February 06, 2020
Tweet

Transcript

  1. Tommy Mühle | tommy-muehle.io Tommy Mühle Software Engineer and Author

    1
  2. Tommy Mühle | tommy-muehle.io Introduce go-mnd 2

  3. Tommy Mühle | tommy-muehle.io A vet analyzer to detect magic

    numbers 3
  4. Tommy Mühle | tommy-muehle.io Magic number? 4

  5. Tommy Mühle | tommy-muehle.io Tommy Mühle | tommy-muehle.io A magic

    number is a numeric literal that is not defined as a constant, but which may change, and therefore can be hard to update. 5
  6. Tommy Mühle | tommy-muehle.io Hide intention 6

  7. Tommy Mühle | tommy-muehle.io Hard to change 7

  8. package main import `github.com/google/go-github/github` func main() { var repo github.Repository

    // ... if repo.GetTeamID() == 12 { // ... } } Tommy Mühle | tommy-muehle.io 8
  9. package main import `github.com/google/go-github/github` const TeamEngineering = 12 func main()

    { var repo github.Repository // ... if repo.GetTeamID() == TeamEngineering { // ... } } Tommy Mühle | tommy-muehle.io 9
  10. Tommy Mühle | tommy-muehle.io How it works 10

  11. Tommy Mühle | tommy-muehle.io 11 >= 1.12

  12. Tommy Mühle | tommy-muehle.io Supported checks 12

  13. package main import ( "net/http" "time" ) func main() {

    client := &http.Client{ Timeout: 5 * time.Second, } // ... } Tommy Mühle | tommy-muehle.io 13 Assignment
  14. Tommy Mühle | tommy-muehle.io 14 package main import ( "fmt"

    "time" ) func main() { t := time.Now() switch { case t.Hour() < 12: fmt.Println("Good morning!") default: fmt.Println("Good evening.") } } Case
  15. package main import "net/http" func handler(w http.ResponseWriter, r *http.Request) {

    // ... http.Error(w, http.StatusText(404), 404) } Tommy Mühle | tommy-muehle.io 15 Argument
  16. package main type queue struct { // ... } //

    ... func (q *queue) MaxLength() int { return 500 } Tommy Mühle | tommy-muehle.io 16 Return
  17. package main func main() { var y int // ...

    x := y * 100 // ... } Tommy Mühle | tommy-muehle.io 17 Operator
  18. Tommy Mühle | tommy-muehle.io 18 package main func main() {

    var x int // ... if x > 100 { // ... } } Condition
  19. Tommy Mühle | tommy-muehle.io Demo 19

  20. Tommy Mühle | tommy-muehle.io 20

  21. Tommy Mühle | tommy-muehle.io 21

  22. Tommy Mühle | tommy-muehle.io 22

  23. Tommy Mühle | tommy-muehle.io 22

  24. Questions?

  25. Thank you! Slides http:/ /bit.ly/2pTywBB @tommy_muehle