Skip to content

Proposal: Reduce Global Variables and Adopt the Options Pattern for Configuration Management #791

@0x0001

Description

@0x0001

Context

I've noticed that the project currently uses some global variables to manage configuration or state in certain modules. While convenient, this can introduce challenges for testing, potential state conflicts, and maintainability.

Proposal

Consolidate the existing global variables into non-global configuration structs, and initialize/pass this configuration using the Options Pattern (also known as Functional Options).

Example Reference

// Proposed usage
client := binance.New(
    binance.WithHMAC("apiKey", "secret"),
    binance.WithTestnet(),
    // ... other configuration options
)

Benefits

  • Reduced Side Effects: Explicitly passing dependencies, avoiding implicit global state.
  • Improved Testability: Easy to inject different configurations for different test cases.
  • Enhanced Readability & Flexibility: Configuration options are passed via explicit function arguments, making code intent clearer and easier to extend with new options.

Next Steps

I would be very happy to implement this change once we reach a consensus.

I'd first like to hear the thoughts of the maintainers and community members:

  1. Does this direction align with the project's long-term architectural goals?
  2. Are there any potential concerns we should be particularly mindful of?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions