-
Notifications
You must be signed in to change notification settings - Fork 160
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
Use opt-in features instead of opt-out #8
Comments
Could you clarify this more? I'm considering switching, but I'm wondering what the/your use case might be, and why it's better. For example, it seems that the most common use of the crate is to use everything, and more specialized consumers will opt out, but this could be wrong. I'd suggest making a poll but I'm not sure enough people use the crate for it to be unbiased ;) |
You use flags like
|
Can you provide a simple PR demonstrating this? Iirc there was some technical reason for using opt-out w.r.t. dryad, but it escapes me at the moment. Perhaps time to get this straightened out before 1.0? Also I think |
There are two distinct concerns here:
These are orthogonal, and actually have very different behaviors: Opt-in vs. opt-out as far as defaults is a matter of preference - generally speaking, if something has no dependencies and no conflicts or concerns, it's often nicer to downstream to enable it by default, Opt-in vs. opt-out regarding feature polarity, however, has exactly one answer: Opt-in. Anything else breaks Cargo. The reason is that Cargo assumes that it is always safe to turn on a feature, and that doing so will never break a dependent. As a result, features with opt-out polarity will get enabled if any dependent asks for them, breaking anyone who uses the now-missing APIs. The correct approach:
[features]
default = ["elf", "elf64", "..."]
But also, beware: Features that change the behavior of an API - like you seem to describe Those kinds of features need to be separate APIs, under different names or modules, with the feature simply enabling them. |
@eternaleye Hey, thank you so much for the detailed write up. Your arguments are compelling, and you convinced me to switch, with some caveats below. The unused boolean in the non endian That being said, I'd like to get your opinion on the Now by definition, this flag disables APIs. There are a few other crates that perform similarly, Before I (or someone else) begins to port the flags to the proposal here, I think a PR demonstrating feasibility or how the no_std/pure version will work, will be required. So some hard, non negotiable requirements for the feature flag port:
If this is possible, I'm OK with the feature flag change. My suspicion is that these requirements are much harder than they seem, but the current reverse polarity setup satisfies all of them... |
Regarding For (1), it's the exact same situation as For (2), the "cannot use byteorder" constraint would mean it should opt out of default features to disable the endian-aware one, and then it would just explicitly enable the appropriate feature flag for the reader. Again, it must ensure that no other crate in the graph depends on goblin with the default features enabled. (3) is trivial, yeah. Of course, all three of these are top-level crates, and so have solid control over their dependency graphs. That makes it relatively easy. While ring's use would be enhanced by either target-specific features or scenarios, I think your use case would benefit most from the latter, allowing "fail-fast" on options being enabled when they are not viable. |
@eternaleye After reading your discussion on the other thread, and your suggestions above, I'm in complete agreement. In fact, I think this should be made much more evident in the cargo docs for feature flags, as the seriousness of using negative polarities isn't nearly crucial enough imho, in addition to many people seem to be implementing the negative polarity approach for whatever reason. Anyway, thanks for your stewardship and help on this matter, I'm glad this was resolved before a serious 1.0 release :) |
Glad to help! And yeah, I agree the Cargo docs really ought to be more explicit about this. |
No description provided.
The text was updated successfully, but these errors were encountered: