-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for File::with_options stabilisation #65439
Comments
Just a thought about an alternative API: let f = File::with_options("file.txt", |o| o.read(true).create(true)); |
From the name I'd associate it with a function that takes an |
LPeter1997, that was my original suggestion but people overwhelmingly preferred this API. |
I agree with @LPeter1997. I think it'd be better to rename it to something like |
I guess
Not that this is a democracy, but let's have a poll: upvote one or more of the following options... |
|
|
|
From the API discovery point of view it's not great to have the only actual verb be the last in chain. From the point of view of making code nicer to read, it's not great that |
This comment has been minimized.
This comment has been minimized.
Update: The team doesn't have bandwidth to deal with bike-shredding about naming of this API, |
FWIW I don't think that having Besides, that's already how the stable OpenOptions works anyway. Furthermore I think that the intent of a line such as: let file = File::options().read(true).create(true).open("foo.txt"); is abundantly clear even if it's the first time you encounter it. And if you don't understand how it's implemented under the hood it's not a huge problem either, since any attempt to reorder the chain to put Regarding the naming I don't have a strong preference, but I do agree that using a I think it's probably worth taking the time to figure out what the conventions should be for these builder patterns in the general case, since whatever convention ends up being adopted by For this reason I very mildly favor the generic |
Why does such a method need to exist in the first place? |
@kanglioo it's just sugar to avoid having to import |
We discussed this briefly in today's @rust-lang/libs meeting. We didn't come to a firm conclusion on naming. We did generally feel like We don't have any specific convention for methods on type X that return a builder type that'll build an X; if we want to use that pattern, we should pick such a convention. We've seen the convention |
I am a fan of the With that said, usually the naming convention is I agree with the libs team meeting consensus that |
Is it feasible to introduce |
@Kinrany I'm personally not a fan of causing churn like that for such a small benefit. |
So it sounds like the So the choice is between
I think I still slightly prefer I don't think we'll ever find a really strong reason to go with either though so maybe it would make sense for the libs team just to do a straw poll amongst themselves and go with one. |
This is a pretty compelling argument, IMO, though I would be fine with |
This goal could also be achieved using inherent associated types (#8995), such that we can add let f = File::OpenOptions::new().create(false).write(true).open("abc")?; |
Since there is already a lot of code with |
I think I'd prefer |
👍 for |
Considering the appearance of what looks like a strong consensus, PR #85766 renames the function to File::options and proposes its stabilization. This is further motivated by the appearance of a strong linguistic convention of |
I'm not entirely convinced that adding I agree with these comments made above:
However, I also agree that having to import OpenOptions separately from File to open a File with some options isn't great either. I think the concerns I mentioned can be addressed by naming it The downside is that In addition, I think it'd be a good idea to check what combinations of options are commonly used, and add new |
@m-ou-se I like
My goodness! I have so thoroughly ignored that area of rustdoc that this is the first time I've realized that its names are sorted lexicographically in contrast to source-order. That's actually pretty useful.
I like |
Also I'm amused that you said you don't think there should be more than one way to do things, but you also want lots of |
Where did I say this? While I consider "fewer ways to do something" a general abstract good thing, it is not a rule I seek to impose everywhere. If I've ever said anything otherwise recently-ish, then I was likely being imprecise. |
FWIW, I think |
I think the argument about whether something sounds like a nullary function or not is valid, and is reasonable grounds to exclude So, I feel it is copacetic either way, and
I am happy to repaint the bikeshed if people can agree on a color! |
On Fri, Jun 04, 2021 at 10:09:34AM -0700, Jubilee wrote:
I think the argument about whether something sounds like a nullary function or not is valid, and is reasonable grounds to exclude `File::with_options()` from the running. But we already have `OpenOptions` as a very... interesting type name. So to me, I agree that nullary `File::open_options()` is quirky, but I also think it's "natural" to Rust, simultaneously, because of the existing legacy of OpenOptions. I believe it's reasonable to lean into the quirkiness. But of course, `File::options()` is also good to me.
One difference is that `OpenOptions` is a type, not a function, so it's
more obvious that `OpenOptions` itself doesn't perform an open
operation. A function named `File::open_options`, living right next to
`File::open`, seems more ambiguous.
I'm not set on the function being called `File::options`; I just don't
think the function name should start with `open`.
|
Sorry, "you" was referring to m-ou-se. |
I'd like to restate that IMO
But I agree that this is a pure bikeshed at this point. If |
Recap
Other IdeasIf the problem is imports, why not just use an ReflectionsRereading this reveals what now feels like a misstep in the early drafts of the I don't think it's a problem that I think the problem is that they are actually logically unrelated, or perhaps I should say that This difference itself would not be a huge issue, honestly, but we have a relatively strong norm of highly "patterned" names in other |
A quick skim of grep.app for Searching for the regexp / / So there's some data: clear as mud! 😃 |
Another possibility: First introduce additional |
This has been stalled for a while and so I'm nominating it for discussion in our next meeting to help it get unblocked. |
The PR stabilizing this feature, #85766, has entered its final comment period with disposition merge. |
Renames File::with_options to File::options, per consensus in rust-lang#65439, and stabilizes it.
Stabilize File::options() Renames File::with_options to File::options, per consensus in rust-lang#65439, and stabilizes it.
Implemented in #65429, behind feature flag
with_options
.The text was updated successfully, but these errors were encountered: