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 upStuttering #66
Comments
This comment has been minimized.
This comment has been minimized.
|
Clippy currently has a lint against types that stutter, but it is disabled by default. |
This comment has been minimized.
This comment has been minimized.
|
There might be some guidance from the C++ world. In particular, Google's C++ style guide disallows |
This comment has been minimized.
This comment has been minimized.
dpc
commented
May 18, 2017
|
IMO, Go forcing everything imported to be qualified by import name did the right thing. |
This comment has been minimized.
This comment has been minimized.
seanmonstar
commented
May 19, 2017
|
An interesting example is the impl fmt::Display for Foo {
fn fmt(&self, f: &muy fmt::Formatter) -> fmt::Result {
// ...
}
} |
This comment has been minimized.
This comment has been minimized.
|
That's an interesting one. For whatever reason, in my code I have found that I prefer this: use std::fmt::{self, Debug, Display};
impl Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/* ... */
}
} |
This comment has been minimized.
This comment has been minimized.
|
I think this should provide at least one canonical guidance for this: https://github.com/rust-lang/rfcs/blob/master/text/0356-no-module-prefixes.md. It's about modules rather than crates, but I think the same reasons apply? I originally saw this convention at https://aturon.github.io/style/naming/README.html#avoid-redundant-prefixes-[rfc-356] too. Note that the RFC mentions |
This comment has been minimized.
This comment has been minimized.
seanmonstar
commented
May 20, 2017
|
As for renaming imports, the most common place I do that is |
This comment has been minimized.
This comment has been minimized.
Kixunil
commented
May 31, 2017
|
I prefer |
This comment has been minimized.
This comment has been minimized.
budziq
commented
Jun 4, 2017
|
Hmm, in reqwest I can see |
This comment has been minimized.
This comment has been minimized.
seanmonstar
commented
Jun 4, 2017
|
True, though the naming was because I don't expect to expose the internal "redirect" module, so they can just be 'Policy' and so on. I suppose they could internally, with a public reexport introducing the prefix, but either option doesn't seem much better in the end. |
This comment has been minimized.
This comment has been minimized.
budziq
commented
Jun 4, 2017
|
So going further with reqwest as an example. Assuming that Redirect module is made public seanmonstar/reqwest#105 should its types be "destuttered" by default along with the export? Or is certain level of repetition is still encouraged as is the case Client::ClientBuilder / Request::RequestBuilder? |
This comment has been minimized.
This comment has been minimized.
jonas-schievink
commented
Jul 22, 2017
|
This came up in kyren/rlua#15, too.
That'd make |
This comment has been minimized.
This comment has been minimized.
Kixunil
commented
Jul 26, 2017
|
@jonas-schievink |
dtolnay
added
the
new guideline
label
Sep 18, 2017
This comment has been minimized.
This comment has been minimized.
carllerche
commented
Aug 8, 2018
|
Any conclusion? I need answers, but have no thoughts :) |
This comment has been minimized.
This comment has been minimized.
|
Not stuttering is good... I like:
|
This comment has been minimized.
This comment has been minimized.
|
Renames are fine too, so long as they don't stutter. Also, I would not love seeing this (which actually stutters too):
|
This comment has been minimized.
This comment has been minimized.
|
People will use module-qualified paths if they are sensible and pervasive in your documentation and usage examples. "Sensible" is a function of number of characters typed and how unique the name is. In my experience people are fine typing 2-3 character modules and mostly fine with 4 character modules. More than that is asking too much, meaning that items in a 5+ character module or library better have a name that can stand alone.
Certain items have somewhat higher thresholds between sensible and not sensible. For |
This comment has been minimized.
This comment has been minimized.
softprops
commented
Sep 11, 2018
|
I've recently been thinking about this specifically in the context of errors https://twitter.com/softprops/status/1038234080305967105?s=19 Being my own devils advocate what this can lead to is overscoping of errors on focused methods. In other words a method in a foo crate that returns foo::Error but in practice may only yield a subset of the total types of errors foo::Error represents. This means clients are asked to handle a representation of errors that won't ever occur in a specific context. Yes this encourages much more focused crates where foo::Error enumerates a very small set of cases but in practice this seems rarely the case. foo::Error typically represents all the cases. |
This comment has been minimized.
This comment has been minimized.
|
The discussion of fine-grained vs broader error types is in #46. If a library or module uses fine-grained errors like the ones returned by std FromStr impls that you linked to, I would expect that they would not all be called |
dtolnay commentedMay 18, 2017
Should it be
log::Levelorlog::LogLevel? This comes up all the time and we've never really settled it as a community. So far we have tended to encourage importing types rather than modules:But this works less well if the type relies on the module name to disambiguate what it means, as in the case of
io::Result.To add to the mess, we have tended to discourage renaming imports.
How do we reconcile all of these?