GithubHelp home page GithubHelp logo

Zero length/capacity makes about lint HOT 3 CLOSED

golang avatar golang commented on September 24, 2024
Zero length/capacity makes

from lint.

Comments (3)

dsymonds avatar dsymonds commented on September 24, 2024

They were intentionally omitted because they don't occur very much in
practice, and the var x = ... form can occur at package-level, which
might matter more.

from lint.

zimmski avatar zimmski commented on September 24, 2024

I did some searching and found two occurrences in the Go source:

http://golang.org/src/pkg/encoding/json/decode.go#L808 -> this is the usual case where make can be removed
http://golang.org/src/pkg/regexp/exec.go#L415 -> Looks to me that this is an optimization because of the API. Every caller of Regexp.doExecute returns nil if there is no match. If there are 0 captures in a regex it can still match and it therefore needs to be not nil. It simply saves the slice header allocation for 0-capture regexes. This looks to me like the big exception.

from lint.

dsymonds avatar dsymonds commented on September 24, 2024

Ultimately this comes down to avoiding too many false positives. Golint can't deduce whether a nil slice can truly be an adequate substitute for an allocated empty slice, so lintMake only looks for constructions that relatively new Go programmers seem to commonly write. It's not intended to capture every possible situation. In my experience of reviewing millions of lines of Go code, I think we've got the balance on this approximately right.

from lint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.