-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Resolve numerous naming conventions #344
Conversation
This RFC proposes to amend the convention to further say: if there is a single | ||
method that is the dominant functionality of the trait, consider using the same | ||
name for the trait itself. This is already the case for `Clone` and `Show`, for | ||
example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show
doesn't quite fit into this category because its method is called fmt
due to sticking with the other formatting traits. (not sure if that affects this convention)
@alexcrichton nits addressed. |
I am especially interested in feedback on the trait naming convention, which I think really affects the terse feel of Rust but which is still pretty vague. |
Update: I've added two new sections after another round of API stabilization: additional iterator method names, and prelude traits. |
Yes, the convention would be maximally clear if it only applied to single-method/capability traits. However, I'd argue that for I think you're probably right about |
Would |
|
d4b4073
to
918b83a
Compare
918b83a
to
513f943
Compare
We're going to have to rework how we do re-exports in libcollections then. See e.g. btree |
I'm a little wary about the |
This is primarily due to the map and set being flattened into a single module, right? I think separating these out was a change we wanted to make anyway. |
It should be the case that these name choices are totally irrelevant to the vast majority of Rust code. But maybe it's worth prototyping these changes to check that's actually the case. |
@aturon btree's map/set are separated out into separate modules, but the parent btree module re-exports things for convenience (same story for the hashmap/set modules). |
@gankro Right. I think maybe we weren't on the same page about what the final state of these would look like. Personally, in the end, I'd prefer for e.g. btree's map and set to show up at the root level as completely independent modules. |
@aturon Would there still be a parent btree module in reality, with the modules just re-exported to the root of libcollections? Or would they both be root-level modules in the actual source tree? |
I don't see anything regarding builder style, which I enjoy: For example, in my curl bindings:
The thing about it is that the builder style usually just sets values on a builder struct, but doesn't follow the set_foo convention. |
Agree with @carllerche. The builder pattern is extremely useful and very flexible. |
@carllerche @reem Oh, definitely! (There's a section on builders in the guidelines already). I'll add a clarification that this new convention does not apply to builders. It's worth thinking a bit about whether builders should expose getters as well (opinions vary) and if so, whether they just follow the reverse convention: |
@carllerche @reem Pushed an update to clarify. I think I'd like to handle builder conventions via a separate RFC -- in particular, I'd like to put the guidelines I wrote earlier through the RFC process. Right now it's mainly a description of how this played out for |
Quiet unrelated to the RFC, but it would be nice if the backing data structure and it's core functions were in a separate file from the, e.g., |
|
Here's a nice naming convention for getters and setters, common in C++. But it requires function overloading:
This one is also compatible with builders. |
@arcto These "nice" getters and setters can't be distinguished with simple text search and aren't encouraged by popular style guides. |
Note: I've pushed a minor update to the lint naming rules, reflecting my experience actually rolling out the conventions. Other than clarifying the existing rules, the main change is standardizing on "unused" (where we previously had "unnecessary", "unused" and "useless"). This matches the |
`&T` | `ref` | ||
`&mut T` | `mut` | ||
`*const T`| `ptr` | ||
`*mut T` | `mut_ptr` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about [T, ..N]
? array
? fixed
? In cgmath we use fixed
.
Should tuples be considered as well? Or should we wait for those conventions to emerge naturally for now? (I haven't seen many tuple conversions yet).
I think the reason that |
[RFC 344](rust-lang/rfcs#344) proposes a set of naming conventions for lints. This PR renames existing lints to follow the conventions. Use the following sed script to bring your code up to date: ``` s/unnecessary_typecast/unused_typecasts/g s/unsigned_negate/unsigned_negation/g s/type_limits/unused_comparisons/g s/type_overflow/overflowing_literals/g s/ctypes/improper_ctypes/g s/owned_heap_memory/box_pointers/g s/unused_attribute/unused_attributes/g s/path_statement/path_statements/g s/unused_must_use/unused_must_use/g s/unused_result/unused_results/g s/non_uppercase_statics/non_upper_case_globals/g s/unnecessary_parens/unused_parens/g s/unnecessary_import_braces/unused_import_braces/g s/unused_unsafe/unused_unsafe/g s/unsafe_block/unsafe_blocks/g s/unused_mut/unused_mut/g s/unnecessary_allocation/unused_allocation/g s/missing_doc/missing_docs/g s/unused_imports/unused_imports/g s/unused_extern_crate/unused_extern_crates/g s/unnecessary_qualification/unused_qualifications/g s/unrecognized_lint/unknown_lints/g s/unused_variable/unused_variables/g s/dead_assignment/unused_assignments/g s/unknown_crate_type/unknown_crate_types/g s/variant_size_difference/variant_size_differences/g s/transmute_fat_ptr/fat_ptr_transmutes/g ``` Since a large number of lints are being renamed for RFC 344, this PR adds some basic deprecation/renaming functionality to the pluggable lint system. It allows a simple mapping of old to new names, and can warn when old names are being used. This change needs to be rolled out in stages. In this PR, the deprecation warning is commented out, but the old name is forwarded to the new one. Once the PR lands and we have generated a new snapshot of the compiler, we can add the deprecation warning and rename all uses of the lints in the rust codebase. I will file a PR to do so. Closes #16545 Closes #17932 r? @pcwalton
This commit renames a number of extension traits for slices and string slices, now that they have been refactored for DST. In many cases, multiple extension traits could now be consolidated. Further consolidation will be possible with generalized where clauses. The renamings are consistent with the [new `-Prelude` suffix](rust-lang/rfcs#344). There are probably a few more candidates for being renamed this way, but that is left for API stabilization of the relevant modules. Because this renames traits, it is a: [breaking-change] However, I do not expect any code that currently uses the standard library to actually break. Closes rust-lang#17917
This commit renames a number of extension traits for slices and string slices, now that they have been refactored for DST. In many cases, multiple extension traits could now be consolidated. Further consolidation will be possible with generalized where clauses. The renamings are consistent with the [new `-Prelude` suffix](rust-lang/rfcs#344). There are probably a few more candidates for being renamed this way, but that is left for API stabilization of the relevant modules. Because this renames traits, it is a: [breaking-change] However, I do not expect any code that currently uses the standard library to actually break. Closes #17917
This commit renames a number of extension traits for slices and string slices, now that they have been refactored for DST. In many cases, multiple extension traits could now be consolidated. Further consolidation will be possible with generalized where clauses. The renamings are consistent with the [new `-Prelude` suffix](rust-lang/rfcs#344). There are probably a few more candidates for being renamed this way, but that is left for API stabilization of the relevant modules. Because this renames traits, it is a: [breaking-change] However, I do not expect any code that currently uses the standard library to actually break. Closes #17917
Rename struct `Entries` to `Iter` in hash/table.rs and hash/map.rs, to match the naming convention of rust-lang/rfcs#344. This is a [breaking-change].
This commit renames a number of extension traits for slices and string slices, now that they have been refactored for DST. In many cases, multiple extension traits could now be consolidated. Further consolidation will be possible with generalized where clauses. The renamings are consistent with the [new `-Prelude` suffix](rust-lang/rfcs#344). There are probably a few more candidates for being renamed this way, but that is left for API stabilization of the relevant modules. Because this renames traits, it is a: [breaking-change] However, I do not expect any code that currently uses the standard library to actually break. Closes #17917
Rename struct `Entries` to `Iter` in hash/table.rs and hash/map.rs, to match the naming convention of rust-lang/rfcs#344. This is a [breaking-change].
This is more in line both with Rust standard library traits, which tend to be transitive verbs, and also with the Rust trait naming conventions RFC rust-lang/rfcs#344, which states: > Prefer (transitive) verbs, nouns, and then adjectives; avoid > grammatical suffixes (like able).
* `linera-core`: add `Persistent` trait * `linera-service`: use new `Persistent` trait * `linera-service`: don't forget to create the file for `persistent::File::new` * `linera-service`: refresh PRNG seed more to align with tests * `linera-service`: rename `Persistent` to `Persist` This is more in line both with Rust standard library traits, which tend to be transitive verbs, and also with the Rust trait naming conventions RFC rust-lang/rfcs#344, which states: > Prefer (transitive) verbs, nouns, and then adjectives; avoid > grammatical suffixes (like able). * `linera-service`: document `Persist` trait * `linera-service::persistent::File`: when an error occurs during error handling, do not hide the outer error * `linera_service::persistent`: single-space documentation Co-authored-by: Andreas Fackler <afck@users.noreply.github.com> Signed-off-by: James Kay <james.kay@linera.io> * `linera-service`: mention bug #2053 * `linera_service::proxy`: replace `expect` with `?` * `linera_service::persistent`: use the indicative mood for function documentation --------- Signed-off-by: James Kay <james.kay@linera.io> Co-authored-by: Andreas Fackler <afck@users.noreply.github.com>
This commit renames a number of extension traits for slices and string slices, now that they have been refactored for DST. In many cases, multiple extension traits could now be consolidated. Further consolidation will be possible with generalized where clauses. The renamings are consistent with the [new `-Prelude` suffix](rust-lang/rfcs#344). There are probably a few more candidates for being renamed this way, but that is left for API stabilization of the relevant modules. Because this renames traits, it is a: [breaking-change] However, I do not expect any code that currently uses the standard library to actually break. Closes #17917
This commit renames a number of extension traits for slices and string slices, now that they have been refactored for DST. In many cases, multiple extension traits could now be consolidated. Further consolidation will be possible with generalized where clauses. The renamings are consistent with the [new `-Prelude` suffix](rust-lang/rfcs#344). There are probably a few more candidates for being renamed this way, but that is left for API stabilization of the relevant modules. Because this renames traits, it is a: [breaking-change] However, I do not expect any code that currently uses the standard library to actually break. Closes #17917
This is a conventions RFC for settling a number of remaining naming conventions:
It also proposes to standardize on lower case error messages within the compiler
and standard library.
Rendered