Skip to content
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

read!() and readbytes!() mutate their second argument #14412

Closed
nalimilan opened this issue Dec 15, 2015 · 5 comments
Closed

read!() and readbytes!() mutate their second argument #14412

nalimilan opened this issue Dec 15, 2015 · 5 comments

Comments

@nalimilan
Copy link
Member

I thought the convention was that in-place versions of functions mutate their first argument. It looks like we could easily change the argument order and print deprecations if we want to enforce this convention.

Though the rand*! family of functions also doesn't follow this rule, so maybe we should just give up on consistency.

@ivarne
Copy link
Member

ivarne commented Dec 15, 2015

It's true that in-place functions mutate their first argument, but IO methods takes an optional ::IO object as the first argument. The question is which convention that should win?

(The ::AbstractRNG interfaces tries to use the same convention as ::IO)

@ScottPJones
Copy link
Contributor

I think @ivarne is correct, which convention takes precedence.
In this case, I personally would prefer to keep the IO as the first argument, even if that causes a little inconsistency with the mutating versions usually modifying the first argument.
It also makes sense if you wanted to have read!(arr) read from STDIN, for example.
(for some reason that short form doesn't seem to exist, though)

@stevengj
Copy link
Member

I agree that io should continue to be the first argument.

@vtjnash
Copy link
Member

vtjnash commented Dec 15, 2015

the mutation of the first argument is common (since it often appears when used for container-semantics and oo-semantics), but I don't think it was ever intended that should be used as a rule. for example, i believe most of the linalg ! functions mutate/assign/overwrite/destroy one or more arguments, but not necessarily the first argument. (unhelpfully, all of the IO functions actually mutate their first argument also, since IO is a form of mutation).

is there a place this needs to be documented better (e.g. when ! is first described in the manual)?

@nalimilan
Copy link
Member Author

To be honest, I haven't read this anywhere (or I don't recall it). No worries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants