-
-
Notifications
You must be signed in to change notification settings - Fork 962
Add Has* methods to simplify checking the state of an Event #76
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
Conversation
39be52c to
0550818
Compare
|
Thanks for taking the time to contribute. But I don't really want to add methods to the Event struct. My preference is to keep a minimal API surface with the bitfields exposed for checking, coalescing, etc. This is based on the design document mentioned in the README. If you wants additional methods like this, it's easy enough to convert to a new type and provide them there. An article on how to do this (and how bitfields work) would be a better approach IMO. Happy to take contributions to the fsnotify.org blog: |
|
I feel like this would be much better if implemented on the As a bonus, if the Event struct is changed to embed Op anonymously these new methods on Op would be promoted to Event without cluttering its' explicit type (or documentation). I don't see any downside to this. Because the current name of the struct field is the same as the type name it should be 100% backwards compatible and references to Event.Op will still work as expected. Like so: |
|
I like this - but why Has? Why not Is? IsCreate, IsWrite, etc. it also wouldn't stop switch code either.
|
|
@matryer But overall, I agree with @nathany, I don't think any more methods should be added. |
|
Yeah. You'd almost do away with the bitmask consts in favour of the methods. But, it's pretty nice as it is too.
|
|
IMHO, the problem with adding these methods is that you either have to unexport the Now overlapping APIs doesn't so bad until you consider that there are 8 backends, so where you need 8 tests, with this new methods you need at least 16, where a feature could have been inconsistent or broken in 8 places, now it can be at least 16. This is unnecessary complexity that can be shifted into it's own package. |
|
It's more an academic discussion about package API design really. I agree that there's no need to change it now.
|
|
The use of bitmasks and creation of a wrapper could be documented on the blog. Would anyone like to write it up? https://github.com/go-fsnotify/fsnotify.org |
|
I'm closing this in favour of documentation or a blog post. See #107. Pull requests to the website repo are welcome. |
Using:
if event.Op&fsnotify.Create == fsnotify.Create {
}
is overly verbose and awkward; a Has() method makes this much nicer:
if event.Has(fsnotify.Create) {
}
PR #76 was previously rejected; I think that HasCreate() etc. is
overkill, but a Has() method makes the library quite a bit more
convenient IMO.
I added it to both the Event and Op to avoid confusion; with this we can
change the Op field to be private in a future v2.
Fixes #107
Using:
if event.Op&fsnotify.Create == fsnotify.Create {
}
is overly verbose and awkward; a Has() method makes this much nicer:
if event.Has(fsnotify.Create) {
}
PR #76 was previously rejected; I think that HasCreate() etc. is
overkill, but a Has() method makes the library quite a bit more
convenient IMO.
I added it to both the Event and Op to avoid confusion; with this we can
change the Op field to be private in a future v2.
Fixes #107
This helps expose a simpler way to query the state of an
Eventwithout resorting to the bitwise query on the raw opcode.I originally named these as
Is*instead ofHas*, but went withHas*since eachEventcan hold multiple states. SoHasseemed more appropriate.I have signed the Google CLA.