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.

Tommy Mühle

February 06, 2020
Tweet

More Decks by Tommy Mühle

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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
  4. package main import ( "net/http" "time" ) func main() {

    client := &http.Client{ Timeout: 5 * time.Second, } // ... } Tommy Mühle | tommy-muehle.io 13 Assignment
  5. 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
  6. 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
  7. package main type queue struct { // ... } //

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

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

    var x int // ... if x > 100 { // ... } } Condition