Would like to see ref and out required for function calls
David Piepgrass
qwertie256 at gmail.com
Tue Sep 11 10:11:12 PDT 2012
> Actually the darndest thing is that C# has retired the syntax
> in 5.0 (it used to be required up until 4.0). Apparently users
> complained it was too unsightly.
>
> Andrei
Wh-huh?? Reference please. I have sought out info about C# 5
multiple times and I never heard that.
Anyway I don't mind if ref is not required, but it ticks me off
that it is not *allowed*. Even in C++ I can use "OUT" and "IN
OUT" at both the definition and call sites (I may as well, since
Windows header files #define them already). The compiler doesn't
verify it but I find it useful to make the code self-documenting.
Some have said that "well if the the compiler doesn't enforce it
then it's pointless, you won't be able to tell if a call site
without 'ref' is passed by ref". But no, it's not pointless,
because (1) if you see a call site WITH 'ref' then clearly it is
passed by reference, (2) I would use 'ref' consistently in my own
code so that when I look back at my code a year later, the
absence of 'ref' is a clear indication that it is an input
parameter, and (3) if the compiler offered the option to issue a
warning when 'ref' is absent, statement (2) would be true 100% of
the time, in my code, instead of just 98%.
Most of the code I look at is my own so that's my primary motive
for wanting 'ref'. Yes, if 'ref' were allowed, some people would
not use it; so when looking at a new code base I'd have no
guarantee that a parameter NOT marked ref is passed by value. But
at least (1) still applies.
More information about the Digitalmars-d
mailing list