DIP 1009--Improve Contract Usability--Preliminary Review Round 1

MysticZach via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 27 18:34:55 PDT 2017


On Wednesday, 28 June 2017 at 01:23:18 UTC, MysticZach wrote:
> On Tuesday, 27 June 2017 at 09:18:11 UTC, Olivier FAURE wrote:
>> A bit late to the party, but I would recommend the following 
>> syntax:
>>
>>     out (void; myTest)
>>
>> for argument-less tests. A casual reader would be less likely 
>> to see this in code and think it's some sort of typo; it would 
>> be easier to google; and it would make some semantic sense 
>> (functions that don't return anything return void).
>
> It's a creative suggestion, and not a bad one. But it's 
> verbose, and I'd like to be able to omit the identifier 
> altogether. Currently, only `for` loops allow this, as when 
> people write:
>
> for( ; ; )
>
> Theoretically, `foreach
>
> foreach( ; a) ...
> out( ; ...)
>
> Currently `foreach` does not allow omitting

Sorry, clicked the `send` button too soon.

Anyway, currently `foreach` does not allow omitting the initial 
identifier, but in theory it _could_ be enhanced to do so. If 
`out` expressions also allow this, then we get the desired 
symmetry between `for`,`foreach`, and `out` expressions, with 
minimal verbosity. That's the solution I promote. It's better 
than requiring something to be there when nothing really has to 
be. I don't know why `foreach` isn't already this way.


More information about the Digitalmars-d mailing list