Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointer receiver on Clear #2

Open
vdemario opened this issue Jul 24, 2018 · 1 comment
Open

Pointer receiver on Clear #2

vdemario opened this issue Jul 24, 2018 · 1 comment

Comments

@vdemario
Copy link

The coexistence of (s Set) and (s *Set) can cause problems. For instance, if a consumer of the library were to create an interface to represent a subset of methods Clear can't go on the same interface as the other methods since Set and *Set are treated as two different types.

There are a few ways to handle this:

  1. The implementation of Clear could be replaced by a slower version that calls Pop until the Set is empty.
  2. Clearcould be removed altogether, leaving the consumer to implement a for loop calling Pop if necessary.
  3. Alternatively, all other methods could be changed to use *Set. This may seem heavy handed at first but since it's not necessary to explicitly take the pointer of a Set variable to call *Set methods this incurs no penalty on the consumer. If Immutable set type / frozenset #1 is implemented it would be a nice symmetry to have the mutable type use a pointer and the immutable type avoid it.
@rjfonseca
Copy link

I like option two. The set could be cleared simply with s = Make()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants