Wishlist proposal, documenting fn arg as in or out or mod
Cecil Ward
cecil at cecilward.com
Tue Jun 20 15:01:17 UTC 2023
I would love to be able to document my arguments as in or out but
also as read-write (like var in pascal, like fortran (?) and C++
D ref.
We already have "in". Good thing.
However it has got mixed up with const so that you can’t declare
something as both. Is that right? I would like the compilers not
to complain if something is declared as "in const" as there are
two independent _intentions_ here, even though of course in
implies const. Apart from that in is great. I use it everywhere.
Small tweak.
Out is perfect as is.
However I hate using ref for input-output arguments as it isn’t
visible at the call site and a ref could be just
ref-for-implementation as in where you want to pass by reference
to avoid copying a large object, but that has nothing to do with
documenting the intention behind the in / out marking of the arg.
Leave ref as it is for those who like it.
So I propose a new keyword either something like modified or mod
or rw or input_output. Beauty contest, I don’t care what wins.
(Shame inout is already taken.)
So my fn might look like
void myfn( in T1 InputArg, in const ref InputArray1, rw Modify,
out result )
What do you think?
Then D would be as good as Ada in this respect, if I can remember
from 40 years ago. ;-)
More information about the Digitalmars-d
mailing list