Discuss naming conventions for traits #28
Replies: 9 comments 6 replies
-
Imperatives should be preferred, especially for traits that perform tasks, since they clearly convey the intention. Having said that it's disappointing that the standard library chose |
Beta Was this translation helpful? Give feedback.
-
Personally, I think |
Beta Was this translation helpful? Give feedback.
-
@Centril I agree. I'd say the naming convention should be "think in plain English". Additionally you can observe that every other naming convention except Agent nouns have their trait's meaning logically linked to the module name. For example, you would think of the
The only exception? Agents. Agents like |
Beta Was this translation helpful? Give feedback.
-
My feeling is that our trait names have nothing to do with imperatives/nouns/adjectives/etc. Instead, trait names adhere to the following rules:
|
Beta Was this translation helpful? Give feedback.
-
Hey @stjepang, your 1 and 2 points are basically the same idea so you could simplify and lump them together ("if the trait exposes mainly one primary method or property/ability, name it like that method or property..." followed by examples). Regarding point 3, describing what implementors are, pertains to the previous classification of agent nouns but you add simple nouns in the mix as well ( In my opinion you've only simplified the classifications a bit but it might detract from meaning which might impede understanding. I do think though that what should come out of this is a more formal explanation of the rules. The rules should be as simple as possible, but not simpler (to quote Einstein, hehe). |
Beta Was this translation helpful? Give feedback.
-
It might also be helpful to write down names of existing traits and fictional traits with slightly different names, then try to guess what would an implementor of each of those traits do. Here's a try... Iteration over lists:
Process termination:
Task execution:
Writing bytes:
Value hashing:
Stack unwinding:
Sending values to other threads:
Unpinning values:
(*) traits that actually exist |
Beta Was this translation helpful? Give feedback.
-
It may also be good to note there is an established convention of using "Ext" as part of an extension trait name. Examples in std: |
Beta Was this translation helpful? Give feedback.
-
Is there an established pattern for third-party crates adding extension traits? For example, we're working on modernizing
Any thoughts on a naming convention to avoid this conflict? Or alternatively, is it best to just accept the name conflict and punt it to API users? Here's a pared down example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e95429439d466dff254454f92851f845 |
Beta Was this translation helpful? Give feedback.
-
@mmastrac that can be handled via unnamed imports use futures::FutureExt as _;
use rust_timers::FutureExt as _; (though that doesn't help with method name conflicts). |
Beta Was this translation helpful? Give feedback.
-
Go has one pretty clear convention for interfaces:
In Rust we have some categories:
io::Write
,fmt::Debug
,clone::Clone
iter::Iterator
,hash::Hasher
fmt::Binary
,ops::Fn
marker::Sized
,panic::UnwindSafe
convert::Into
,borrow::ToOwned
Are there any conventions we can distill out of this or is it a free-for-all?
Beta Was this translation helpful? Give feedback.
All reactions