Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 07, 2012 Would like to see ref and out required for function calls | ||||
---|---|---|---|---|
| ||||
I've been looking at migrating a reasonably large ship motion library (tens of thousands of lines) from C# to D. I've become quite enthusiastic about D, and most of my problems have been relatively minor (e.g., inconsistent bugs with std.container.Array, would like orange serialization to give me an error telling me I didn't register a class before calling serialize). I suggest that the language require ref and out when calling functions, as C# requires. This would make code easier to understand, and would also eliminate the problem I had when the wrong function from the following choices was mistakenly called: parseLineInts(string text, int positionStart, out int j0, out int j1) parseLineInts(string text, out int j0, out int j1, out int j2) I note that the second function calls another function as follows: int positionStart = 1; parseLineInts(text, positionStart, j0, j1, j2); I look forward to seeing feedback from D experts. This is the only significant change that I could think of recommending for the language. |
September 07, 2012 Re: Would like to see ref and out required for function calls | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kevin McTaggart | On 9/7/12 1:34 PM, Kevin McTaggart wrote:
> I've been looking at migrating a reasonably large ship motion library
> (tens of thousands of lines) from C# to D. I've become quite
> enthusiastic about D, and most of my problems have been relatively minor
> (e.g., inconsistent bugs with std.container.Array, would like orange
> serialization to give me an error telling me I didn't register a class
> before calling serialize). I suggest that the language require ref and
> out when calling functions, as C# requires. This would make code easier
> to understand, and would also eliminate the problem I had when the wrong
> function from the following choices was mistakenly called:
>
> parseLineInts(string text, int positionStart, out int j0, out int j1)
>
> parseLineInts(string text, out int j0, out int j1, out int j2)
>
> I note that the second function calls another function as follows:
> int positionStart = 1;
> parseLineInts(text, positionStart, j0, j1, j2);
>
> I look forward to seeing feedback from D experts. This is the only
> significant change that I could think of recommending for the language.
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
|
September 07, 2012 Re: Would like to see ref and out required for function calls | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 9/7/12, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote: > 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. If you like implicit ref then why did you choose to use pointers when implementing std.getopt? |
September 07, 2012 Re: Would like to see ref and out required for function calls | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 9/7/12 4:55 PM, Andrej Mitrovic wrote:
> On 9/7/12, Andrei Alexandrescu<SeeWebsiteForEmail@erdani.org> wrote:
>> 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.
>
> If you like implicit ref then why did you choose to use pointers when
> implementing std.getopt?
At the time ref variadics weren't implemented. I should also add I joined D after ref was there. I don't have strong feelings one way or another.
Andrei
|
September 07, 2012 Re: Would like to see ref and out required for function calls | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kevin McTaggart | On Friday, September 07, 2012 13:34:02 Kevin McTaggart wrote:
> I look forward to seeing feedback from D experts. This is the only significant change that I could think of recommending for the language.
Regardless of the pros and cons of requiring explicit ref and out, it would break a lot of code if we started requiring it, so I don't think that there's any chance of such a change being made at this point. If/When we create D3 (which is years off), it could be discussed and possibly changed then, but I think that it's clearly too large a change for D2 at this point.
- Jonathan M Davis
|
September 07, 2012 Re: Would like to see ref and out required for function calls | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Am 07.09.2012 16:38, schrieb Andrei Alexandrescu:
> 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.
reference link?
|
September 07, 2012 Re: Would like to see ref and out required for function calls | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 09/07/2012 04:38 PM, Andrei Alexandrescu wrote:
> ...
> 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
>
>
How do they deal with the increased ambiguity in overload resolution?
|
September 07, 2012 Re: Would like to see ref and out required for function calls | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On 09/07/2012 05:51 PM, Timon Gehr wrote:
>
> How do they deal with the increased ambiguity in overload resolution?
Actually, it is simple. They just have to call the non-out overload
when there is no out at the call site, regardless of the actual
argument.
|
September 07, 2012 Re: Would like to see ref and out required for function calls | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu: > 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. Are you sure? This page about the Visual Studio 2012 shows that ref and out are required: http://msdn.microsoft.com/en-us/library/14akc2c7.aspx I know they have relaxed the requirement in one case, in C#4 or something. The idea of requiring ref/out at the all site was discussed some times in past. This idea has both advantages and disadvantages. It makes the code a bit longer, but gives the reader more information about what the call will do. In D there are also ref at the return value, I presume this is never going to require a "ref" at the call site. Bye, bearophile |
September 07, 2012 Re: Would like to see ref and out required for function calls | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Friday, 7 September 2012 at 16:46:36 UTC, bearophile wrote:
> Andrei Alexandrescu:
>
>> 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.
>
> Are you sure?
> This page about the Visual Studio 2012 shows that ref and out are required:
> http://msdn.microsoft.com/en-us/library/14akc2c7.aspx
+1
|
Copyright © 1999-2021 by the D Language Foundation