Binding rvalues to ref parameters redux

bitwise bitwise.pvt at gmail.com
Thu Mar 28 19:59:20 UTC 2019


On Thursday, 28 March 2019 at 16:14:04 UTC, Andrei Alexandrescu 
wrote:
> On 3/28/19 10:36 AM, bitwise wrote:
>> On Wednesday, 27 March 2019 at 01:38:40 UTC, Andrei 
>> Alexandrescu wrote:
>>> Work has been underway on redoing DIP 1016. I haven't made a 
>>> pull request yet as it's a bit early. Looking for high-level 
>>> observations:
>>>
>>> https://gist.github.com/andralex/e5405a5d773f07f73196c05f8339435a
>>>
>>> Thanks in advance for any feedback.
>> 
>>  From the response to DIP 1016:
>> 
>>> Here, the DIP Author clearly expresses two reasons why a 
>>> programmer may choose to declare a function to accept `ref` 
>>> arguments. The Language Maintainers see this as the core of 
>>> the proposal and would expect the distinction between the two 
>>> cases to be maintained throughout. [However, this proposal 
>>> does not maintain the distinction and instead conflates the 
>>> two][1] cases. The Language Maintainers insist that any 
>>> proposal allowing `ref` parameters to accept rvalue 
>>> references must clearly define how functions which make use 
>>> of `ref` for side effects will not accept rvalues.
>> 
>> I don't see anything in the new DIP that addresses the above 
>> issue. [1]
>
> The nonassignability requirement addresses it.

I agree that the nonassignability requirement fills a major 
pothole, but it doesn't address the issue of expressing your 
intent as the writer of a function with ref parameters. The 
caller may have trouble determining if a function will modify the 
argument passed to it. The issue could be mitigated by 
function/parameter naming convention, comments, documentation, or 
providing source code to the caller, but all of these solutions 
have the potential to be spotty or absent, so I believe something 
should be done to make the writer's intent clear to the caller.


More information about the Digitalmars-d mailing list