Code Monkey home page Code Monkey logo

Comments (10)

pgier avatar pgier commented on May 22, 2024 1

I agree that it seems better to remove the top level constructor functions and just always require fs to make the API more consistent. So once the current set of PRs are merged, I'll create another PR to:

  1. remove the top level NewThing() constructor functions
  2. change the FS methods from NewThing() to Thing()
  3. since FS would now be required in most/all cases, maybe add a new FS constructor such as NewDefaultFS() for when /proc and /sys are in the default locations.

from procfs.

mdlayher avatar mdlayher commented on May 22, 2024

I'd also like to suggest that we get rid of constructor functions like NewBuddyInfo in favor of methods like: FS.BuddyInfo, because:

  • it will shrink the API surface
  • it will reduce redundancy
  • it will enable much easier testing

from procfs.

grobie avatar grobie commented on May 22, 2024

@mdlayher You mean all package level shorthand methods? Even Self()?

from procfs.

mdlayher avatar mdlayher commented on May 22, 2024

Good question. I suppose it depends how much some of them are used. While they may be convenient, I imagine that most applications will want to construct a FS instance anyway for testing that doesn't only work on Linux machines.

from procfs.

pgier avatar pgier commented on May 22, 2024

Is this something that we still want to do? After the refactoring in #149, we still have a lot of method names that look like fs.NewSomething(). Using the BuddyInfo example, we have NewBuddyInfo() and fs.NewBuddyInfo(). We could change the fs method to fs.BuddyInfo() however the top level function, can't be changed to just BuddyInfo() because then it conflicts with the BuddyInfo struct. Maybe we can change top level functions to something like ReadBuddyInfo() instead?

from procfs.

discordianfish avatar discordianfish commented on May 22, 2024

I think the idiomatic way would be to call it BuddyInfo() and rename the struct instead..

from procfs.

discordianfish avatar discordianfish commented on May 22, 2024

See the linked PRs. I think fs.BuddyInfo() is the way to go and I tend to say we should call the package level functions that do the same should also be called the same but that's somewhat against prefixing "top level constructor functions" with New.. @mdlayher Would love your 2 cents on this.

from procfs.

mdlayher avatar mdlayher commented on May 22, 2024

I still agree with my previous comment: #44 (comment)

I'd like to see very few package level functions, and everything is only accessible via a method on the FS type.

from procfs.

discordianfish avatar discordianfish commented on May 22, 2024

Don't have a opinion on that, so if you think that's better - let's do it.

from procfs.

pgier avatar pgier commented on May 22, 2024

Fixed in PR #162

from procfs.

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.