-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
Note: This topic has an extensive discussion on https://discourse.julialang.org/t/notation-for-individual-modified-variables/9653 The proposal received some positive feedback there, so I'm reposting it here as a "more official" proposal.
Context
The ! style recommendation for functions that modify their parameters proves extremely useful to me.
Issue
For certain functions with many arguments, functionname!(foo, bar, baz) can be ambiguous: How do I know if foo, bar or baz gets modified, or if potentially multiple parameters get modified?
Proposal
I propose a style convention that clarifies which parameters will be modified. I imagine appending a ! to each modified parameter. If functionname! modifies foo and baz, its declaration would read functionname!(foo!, bar, baz!).
Perks
This convention could improve readibilty in two ways:
- Function docs could be more readable, since one could immediately infer the modified argument(s), and would not have to rely on guesswork.
- Function code could be more readable, since one can keep track of the mutated parameter, which is often the "most important" one.
In addition, someone proposed that if this became widely adopted, the compiler could use the information to speed up the code.