4 ms·
The boolean example is particularly bad though; I believe it is even in the Rust API Guidelines to not pass booleans in your APIs precisely for that reason. The
by solmag 5y ago
The boolean example is particularly bad though; I believe it is even in the Rust API Guidelines to not pass booleans in your APIs precisely for that reason. The advice which I agree with is to make it properly typed
https://rust-lang.github.io/api-guidelines/type-safety.html?highlight=bool#arguments-convey-meaning-through-types-not-bool-or-option-c-custom-type https://rust-lang.github.io/api-guidelines/type-safety.html?...
- hota_mazi 5y agoBut the recommendation sounds like it's trying to work around a limitation of the language. "We don't support named parameters, therefore, create an enum whenever a boolean would have been enough with proper support of named parameters". I think this is unsound reasoning, but regardless of whether you agree with this or not, the idea of creating an enum for every boolean that gets passed to a function sounds pretty crazy to me. If you have named parameters, you just don't need to create an enum whenever you are passing a boolean to a function.
- solmag 5y agoI think it's good the way the Rust API guidelines lay it out. It will also introduce additional lightweight documentation (in form of a type) and reduces amount of raw booleans in the code, and will get the benefits of the advanced type system too, and somewhat future proofs it that way too.