Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: Resolve numerous naming conventions #344
Conversation
alexcrichton
reviewed
Oct 1, 2014
| 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. |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Oct 1, 2014
Member
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
reviewed
Oct 1, 2014
| the plural form: use `unused_variables` rather than `unused_variable`. | ||
| This makes `#[allow(unused_variables)]` read correctly. | ||
|
|
||
| * Use underscores to separate words in the same way you would for function names. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton nits addressed. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
Update: I've added two new sections after another round of API stabilization: additional iterator method names, and prelude traits. |
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
arcto
commented
Oct 1, 2014
|
Would |
This comment has been minimized.
This comment has been minimized.
arcto
commented
Oct 1, 2014
|
|
aturon
force-pushed the
aturon:conventions-galore
branch
from
d4b4073
to
918b83a
Oct 1, 2014
aturon
force-pushed the
aturon:conventions-galore
branch
from
918b83a
to
513f943
Oct 1, 2014
This comment has been minimized.
This comment has been minimized.
We're going to have to rework how we do re-exports in libcollections then. See e.g. btree |
This comment has been minimized.
This comment has been minimized.
|
I'm a little wary about the |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
|
@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). |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
@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? |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
reem
commented
Oct 1, 2014
|
Agree with @carllerche. The builder pattern is extremely useful and very flexible. |
This comment has been minimized.
This comment has been minimized.
|
@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: |
This comment has been minimized.
This comment has been minimized.
|
@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 |
This comment has been minimized.
This comment has been minimized.
|
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., |
This comment has been minimized.
This comment has been minimized.
reem
commented
Oct 2, 2014
|
|
This comment has been minimized.
This comment has been minimized.
arcto
commented
Oct 2, 2014
|
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. |
This comment has been minimized.
This comment has been minimized.
|
@arcto These "nice" getters and setters can't be distinguished with simple text search and aren't encouraged by popular style guides. |
This comment has been minimized.
This comment has been minimized.
I think |
This was referenced Oct 9, 2014
alexcrichton
referenced this pull request
Oct 10, 2014
Closed
non_uppercase_statics should be renamed for constants #17932
This comment has been minimized.
This comment has been minimized.
|
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 |
brendanzab
reviewed
Oct 14, 2014
| `&T` | `ref` | ||
| `&mut T` | `mut` | ||
| `*const T`| `ptr` | ||
| `*mut T` | `mut_ptr` |
This comment has been minimized.
This comment has been minimized.
brendanzab
Oct 14, 2014
Member
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).
This comment has been minimized.
This comment has been minimized.
|
I think the reason that |
aturon commentedOct 1, 2014
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