Giter Club home page Giter Club logo

Comments (7)

victorkt avatar victorkt commented on July 17, 2024 3

Apologies if this was already discussed and I realise I might be a bit late to this, but have you considered using functional options? It's an idiomatic and common way of passing options in Go.

As an example, I can point to OpenTelemetry's implementation for instrumentation options.

For OpenFeature, it could look something like this:

val, err := client.BooleanValue(
  "someFlag",
  false,
  openfeature.EvaluationContext{},
  openfeature.WithHooks(...),
  openfeature.WithHints(...),
)

All options would be optional, and It achieves something similar to what is being proposed here. One drawback of the current proposed approach would have to deal with multiple EvaluationOptions objects being passed (either ignoring or merging them).

from go-sdk.

toddbaert avatar toddbaert commented on July 17, 2024 2

@victorkt @skyerus ... what's not to like about this option?! Makes sense to me. I give it a +1.

Thanks for the suggestion.

from go-sdk.

james-milligan avatar james-milligan commented on July 17, 2024 1

I prefer the variadic approach, it makes for a cleaner interface

from go-sdk.

skyerus avatar skyerus commented on July 17, 2024

I've opened PRs for two potential improvements to the client API, we need to decide which approach is preferable (I prefer the second), or perhaps some combination of the two.

  1. #63
    This separates the flag calls into two, the first is a simplified call without the EvaluationOptions parameter, the second is as before. This retains the enforcement of including the EvaluationContext in all flag resolution calls.

  2. #64
    This also separates the flag calls into two, both of which now have EvaluationOptions as a variadic parameter in order to simulate an "optional" parameter.
    The original is now a simplified call without the EvaluationContext parameter with the addition of a new WithContext func that includes the EvaluationContext parameter.

@james-milligan @beeme1mr @toddbaert

from go-sdk.

skyerus avatar skyerus commented on July 17, 2024

@toddbaert does your approval of #63 mean that's your preferred approach? James & I prefer the other approach

from go-sdk.

skyerus avatar skyerus commented on July 17, 2024

We settled on a middle ground approach of retaining the EvaluationContext as a first class parameter and making the EvaluationOptions variadic

from go-sdk.

skyerus avatar skyerus commented on July 17, 2024

Thanks for the eloquent explanation and example.
While I haven't seen this approach used in function calls (only seen in constructors e.g. func NewFoo()), I don't see why we couldn't.
I actually think this is cleaner than our current variadic EvaluationOptions, I'm all for it.
Interested to hear some other opinions on the matter though @james-milligan @toddbaert @beeme1mr @davejohnston

from go-sdk.

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.