Would like to see ref and out required for function calls

Manuel manuel at d.org
Wed Sep 12 16:02:31 PDT 2012


On Wednesday, 12 September 2012 at 07:36:24 UTC, Paulo Pinto 
wrote:
> On Tuesday, 11 September 2012 at 16:49:45 UTC, Manuel wrote:
>> 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.
>>
>
> Having used Turbo Pascal before I was doing C, I never 
> understood
> why so many developers cry for this at the call site.
>
> I never had any problem with "var" parameters on Turbo Pascal 
> (or
> other languages from Wirth), nor with references in C++.
>
> As I am not language religious, I just use them the way the
> language provides them.
>
> --
> Paulo


You just have cut away the last part of the history of my life 
and completely changed my statement to the reverse ;-)

That last part was were i was getting my enlightenment and 
started to embrace additional annotations at the call site. From 
there i never looked back and lived a happier and more glorious 
life with a lot of profit and lot less errors ;-)


Kevin just put this up for discussion because he realized while 
porting code from C# to D that he got wrong function calls on 
overloaded functions because of missing call site parameter 
annotations and just asked about the general opinion in the D 
community to add these to the language.

I and a lot of the other participants in this thread just 
asserted that it would be a nice addition to D. That does not 
mean, we were "crying" for these or that we are "language 
religious" or that without them we would have unsolvable problems 
and would forever quit programming in D and switch over to 
QuickBasic again.

It was more just a survey about the general opinion in the 
community. And as an intermediate result (which is not even close 
to be representive), the majority of the participants of this 
thread would like to have these added to the language, some just 
don't care and some don't like the idea at all.

 From those who didn't like the idea the most heared 
counter-argument was more like: "I know my code, i have written 
it, so i know which method modifies which parameters. I don't 
need this it makes me do more work."

Which in my opinion is a bit shortsighted since in commercial 
development or in general when you work in a team you don't 
program in isolation and you have to  often use 
third-party-frameworks were you don't have written every method 
by yourself. That's why the Microsoft language designer added 
this to C# and you even find this in a simulated way in C++ 
realised with references and pointers.

The only valid counter-arguments brought up so far, were possible 
breakage of code (when it would be enforced) and maybe UCFS.


> As I am not language religious, I just use them the way the
> language provides them.


The good thing here in the open source world is that we are not 
bound to the decision of a big committee. It's not "you'll eat 
what's put in front of you".

If a bigger part of the D community would like to have these 
annotations added to the language, at least as an optional 
feature, then that might persuade our "benevolent dictators" 
(just joking - you are great!) Walther and Andrei to add them or 
we could just make a fork of the language and add them ourselves 
(more joking - no, just skip this last part - it's late) :-)

There might be other problems, maybe with the compiler internals 
or breakage of parts of the language. These were severe. But i 
think only Walther and Andrei might tell. If these wouldn't exist 
it would at least be possible, how David proposed it in his post, 
to make them optional.

At the end that won't stop me or any other poster from 
programming in D. It would just really be nice to see this little 
extra of parameter checking at least optionally in D since with 
all the other safeness-features like safeD, contracts, etc. it 
would be a good addition to the language.





More information about the Digitalmars-d mailing list