Skip to content

Look for pesky make usage in Go code

License

Notifications You must be signed in to change notification settings

admacleod/triplemake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TripleMake

The 2 argument form of make can cause all sorts of fun bugs that can be difficult to debug. This linter finds those uses and alerts you that perhaps you should consider changing them to the 3 argument form to be more explicit.

An example

package main

import "fmt"

func main() {
	// Premature optimisation: we only want to put 5 items into this slice.
	test := make([]int, 5)

	// Oops!
	test = append(test, 1)

	fmt.Println(test) // [0 0 0 0 0 1]
}

A quick rant

This is bad DX on the part of Go. The difference between Length and Capacity of slices can be difficult to understand for the kinds of people who like to do premature optimisation, and debugging this can be tricky too.

About

Look for pesky make usage in Go code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages