mirror of
https://github.com/ruuda/rcl.git
synced 2025-12-23 04:47:19 +00:00
Naming these was a long bikeshed. Some considerations: * Symmetry with Set.to_list and String.to_uppercase, keep the to_. * Naming after an action is clearer than naming after a property, because for a property it's not clear whether that is a precondition rather than a postcondition. xs.dedup() makes it clear it removes duplicates, xs.unique(), does it assert it's unique? Does it test it? * In light of the above observation, List.sort is a good name, better than List.sorted. * The obvious one people will try is probably to_set. If it silently drops duplicates, that's an unsafe default. So let's make this the one that validates, and we can have to_set_dedup that drops duplicates. * Erroring on duplicates is always safe. We can even point the users to the version that drops duplicates. * If you read code and see xs.to_set() without any contrasting .to_set_dedup(), it's not so obvious that .to_set() does any validation, and if that is your intent, then you have to clarify that in a comment. * xs.to_set_assert_unique in that sense is clearer, but it's too verbose in practice. xs.to_set_nodup is a bit obscure, especially if you don't see the contrasting .to_set_dedup(). * A method List.dedup that returns a list, and having to_set being the one that errors, also works, then you can do .dedup().to_set(), which is very explicit. It still does not clarify at the call site that to_set is validating though. It is also inefficient, but that's probably not a problem for RCL, and you can always use a comprehension if it matters. So conclusion for now, to_set is the right prefix for symmetry and discoverability. There is not going to be a "default" to set, you have to explicitly choose whether you want to discard duplicates or not. The to_set_dedup is clear for that. When reading code, to_set_unique is maybe less obvious, but it gives more hint than to_set, and if you think for a moment, set values are already unique, so why the _unique, and then you find the contrast with _dedup. So far this seems like one of the better directions. |
||
|---|---|---|
| .. | ||
| fuzz_targets | ||
| src | ||
| tools | ||
| .gitignore | ||
| Cargo.rcl | ||
| Cargo.toml | ||
| dictionary.txt | ||
| dictionary_base.txt | ||
| dictionary_cli.txt | ||