Git Product home page Git Product logo

Comments (3)

jszwec avatar jszwec commented on June 4, 2024

Both of the proposed solution are not great

type Option func(*s3FSoptions)

You should not use unexported types args on exported functions. Even linters are picking these up

type Option interface{
    apply(*S3FS)
}

This is also a bad idea. You should not expose interfaces that cannot be implemented by anything from outside the package.

I don't think this is an issue at all. Look at Go's standard libraries, there are lots of options that are not safe for similar reason. Even JSON decoder... Usually things like this are dealt through documentation by saying something like
"Options should be applied before the first use"
At the end of the day, this is not a problem if you use it correctly and that's how many libraries even in Go standard library work today. If you want to misuse it then you are probably doing it on purpose, because why would anyone start a go routine and call WithOption() or do it in the middle of for loop

from s3fs.

sagikazarmark avatar sagikazarmark commented on June 4, 2024

You should not expose interfaces that cannot be implemented by anything from outside the package.

That's exactly the point though: this interface should and never will be implemented or called outside of the package. (Yes, what you say makes sense in 99% of the cases...this is the exception)

Both of the above solutions are established patterns to prevent abuse of functional options.

The problem usually isn't the fact that people do it on purpose, but that fact that they don't know that's a problem. It's probably not that big of an issue here and won't cause any concurrency problems, but it's usually better to be on the defensive side and these patterns help with that.

Anyway, I reported the issue, up to you if you want to do anything about it or not. Feel free to close if you don't think it's a problem. Thanks for replying.

from s3fs.

jszwec avatar jszwec commented on June 4, 2024

That's exactly the point though: this interface should and never will be implemented or called outside of the package. (Yes, what you say makes sense in 99% of the cases...this is the exception)

Both of the above solutions are established patterns to prevent abuse of functional options.

I disagree with both.

Can you do it?
yes
Should you do it and it's idiomatic?
no

Thanks for reporting but I don't think this is an issue. Every code and library can be misused and abused, we can't protect against everything

from s3fs.

Related Issues (3)

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.