On Tuesday, 11 September 2012 at 08:10:21 UTC, Andrei Alexandrescu wrote:
On 9/11/12 1:28 AM, Manuel wrote:
Citation? I'm using C# 5.0 with Visual Studios 2012 on Windows 8 right now and ref/out are still required at the call sight of functions.

I have Visual Studio 2012 RC and can confirm, that ref and out
are still required even with C# 5.0 (but maybe there is some
compiler switch to disable this ??)

Erik Meijer didn't get back to me yet about that with a link, but he did mention that the relaxation was only allowed for COM calls.

Andrei

OK, i see. For COM calls that might make sense, since binary COM modules are mostly written in C/C++ and must also not depend on any feature of any programming language so that the calling should be easily possible from any language. There these C# specific annotations are of no use since you don't get any additional safety and you just have to write more code which at the end gains you nothing.


In general, i can understand the objections against adding these syntax annotations at the call site. When i started programming in C#, coming from a C++ background, i found writing these additional annotations rendundant and annoying and a complete waste of time.

But when you are developing in a team where you often have to read the code written by other team members and they have to read your code, then you really begin to see the merits. But it is also a good reminder for yourself when you have to look or modify code you have written a long time ago.


A colleague of mine also mentioned, that you can see "a simulation" of the ref/out annotations using pointers / references as an idiom nowadays in a lot of C++ code too. If a function argument will be modified in some way you use a pointer and const references when it won't:


e.g. if you have a function / method:


void transmogrify(const MogrifyType& a, const MogrifyType& b, MogrifyType* out)


you would call it:


transmogrify(a, b, &c);


Using this convention throughout the code you can see at the call site that a and b are input parameters and c will be modified.

For example the render system "pbrt" ( http://pbrt.org/ ) uses this as an convention in their C++ code and it is explicitly mentioned in chapter 1.5.1 "pointer or reference" in the introduction.

Reply via email to