-
Notifications
You must be signed in to change notification settings - Fork 17.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
os: make os.OpenFile() 'perm' argument variadic to match POSIX open
signature
#35647
Comments
Thanks for the suggestion. This would break backward compatibility, so it's not something that can be done for Go1. https://golang.org/doc/go1compat
It may be considered for Go2, I guess. |
I do not like this idea, personally. Variadic arguments in C are strictly seen as "additional arguments" and really don't have any additional meaning. This means that variadic arguments in C are used sometimes to express optional arguments, as they are with In Go, variadic arguments are represented as a slice, which brings the convention that many arguments should be acceptable as a valid input. In this case, we would only want a single FileMode argument to be passed as a bitflag (if we want to keep it close to the POSIX syscall). I think requiring the bitflag is a bit more "loyal" to the original syscall than allowing multiple FileModes to be passed. |
@deanveloper doesn't the POSIX system call itself theoretically allow for multiple For example, the following compiles and runs on Linux
I noticed that the interfaces for |
@ALTree I wanted to ask about the 'backward compatibility' requirement mentioned in the link you provided for Go1.
Does If users invoke
For the line Thanks. |
You are not mistaken, that's pretty much spot on IIRC. Note that if you supply any more than one argument for the variadic arguments, they will be ignored, and it's not really logical for them to be anything but that. This is because C does not specify a length for it's variadic arguments, just as it does with arrays. The way it can even tell that you supplied a variadic argument is if you specified the That's getting a bit off topic though. Getting back to the proposal - I personally think it's better to leave OpenFile as-is, however I can see the justification for making it variadic.
|
Optional arguments are form of function overloading, and Go doesn't have or want function overloading. If we feel that this is important, then, rather than changing the signature of |
What are you proposing?
The
os.OpenFile
interface takesperm FileMode
as a required argument. Sinceperm
is only relevant inos.O_CREATE
(basing this statement off of POSIXopen
), it would make more sense for it to be a variadic/optional argument with a signature like the one below.Why are you proposing this?
The proposed change to the
os.OpenFile
function signature will make it resemble the POSIX function signature for theopen
system call.The text was updated successfully, but these errors were encountered: