Coder Social home page Coder Social logo

Comments (4)

mark-kubacki avatar mark-kubacki commented on September 27, 2024 1

I've not been 100% sure when to use a pointer and when not. And, as far as I remember, Go manages structs as pointers anyway; and by this—perhaps flawed—understanding returning a pointer to struct would indeed be using a double-pointer, and indirect reference (**T in C).

Usage of pointers as wanted by func (t *Version) f()… would be kinda flattened by the compiler anyway. This in mind I failed to see any benefits to func (t T) f()… and went with the former.

from semver.

mark-kubacki avatar mark-kubacki commented on September 27, 2024

Sure! Same goes for whenever you see opportunities to improve the interface.

from semver.

mholt avatar mholt commented on September 27, 2024

Actually, nevermind -- it creates allocations in the benchmarks which are currently 0, and slows it down by about 20ns. I'll just handle the referencing when needed. Thanks!

from semver.

mark-kubacki avatar mark-kubacki commented on September 27, 2024

Turns out I've been wrong: The compiler won't flatten any pointers or optimize this in any way. (With the exception of &T for a f(… *T), and arrays.)

That's the why for version 3: value receivers where possible. If you (or someone else reading this) doesn't like it, keep importing version 2 and do reach out. I'll consider any back-porting if v2 is not too old by then. It's not that there are any other big functional changes between the two.

I've not made up my mind about whether to refactor any []*Version to []Version—which would then be grounds for releasing a version 4—for I need to learn the best solution for sorting and map-reduce. In any case, the pointer receiver to NextVersion can and will be replaced come the next minor revision in v3 (I don't see why anyone would call NextVersion∙NextVersion).

from semver.

Related Issues (6)

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.