google / renameio

Package renameio provides a way to atomically create or replace a file or symbolic link.
Apache License 2.0
609 stars 27 forks source link

TempFile: name bikeshedding #2

Closed mvdan closed 6 years ago

mvdan commented 6 years ago

Moved from Twitter at https://twitter.com/mvdan_/status/1057290763254546434

I'm not a big fan of code like:

tf, err := write.TempFile("", "foo")

Reading it for the first time, it seems to say "write a temporary file called foo", similar to how ioutil.TempFile creates a temporary file named after a string.

I think the name should convey "write a file called foo". If there's only going to be this implementation through a temporary file, then I'd just call it write.File.

If there are going to be other PendingFile constructors, I do understand the need to add something to this one's name. Some ideas that come to mind are write.WithTemp, write.ViaTemp, write.TempTo, or even write.NewTemp, since the constructor doesn't actually write anything.

stapelberg commented 6 years ago

I like the write.File suggestion the most thus far. I’ll keep this open in case other people have suggestions, too, and then we can eventually pick a winner.

mvdan commented 6 years ago

If there are going to be no other PendingFile constructors, I agree it's the best option.

stapelberg commented 6 years ago

Given the new package name (and with the hypothetical WriteFile from issue #3 being the new preferred entry point), do you still see a need to change the name? I think renameio.TempFile sounds reasonable.

mvdan commented 6 years ago

It's less of a problem - it no longer reads "write temp file". Now it just reads "temp file", which is more ambiguous. So I don't think it gets closer to what the API actually does, but at least it doesn't imply something completely different.

Assuming we can't come up with a better name, renameio.TempFile sounds okay.

stapelberg commented 6 years ago

Closing this as #3 is now resolved, and we agreed that the current name is good enough.