DIP 1003 Formal Review
via Digitalmars-d
digitalmars-d at puremagic.com
Sat May 13 07:30:38 PDT 2017
On Saturday, 13 May 2017 at 10:27:25 UTC, Timon Gehr wrote:
> On 12.05.2017 18:17, Mike Parker wrote:
>> The first stage of the formal review for DIP 1003 [1], "Remove
>> body as a
>> Keyword", is now underway. From now until 11:59 PM ET on May
>> 26 (3:59 AM
>> GMT on May 27), the community has the opportunity to provide
>> last-minute
>> feedback. If you missed the preliminary review [2], this is
>> your chance
>> to provide input.
>>
>> At the end of the feedback period, I will submit the DIP to
>> Walter and
>> Andrei for their final decision. Thanks in advance to those of
>> you who
>> participate.
>>
>> [1]
>> https://github.com/dlang/DIPs/blob/fbb797f61ac92300eda1d63202157cd2a30ba555/DIPs/DIP1003.md
>>
>>
>> [2]
>> http://forum.dlang.org/thread/qgxvrbxrvkxtimzvnetu@forum.dlang.org
>
> Option 1 is good: There is nothing wrong with the current
> syntax. [1]
>
> Option 2 is bad: It's the function body, not the function.
>
> Option 3 is ugly: There is no precedent for '...{}{}' belonging
> to the same declaration or statement.
Hmm, I guess it depends on how you format your code. I noticed
that you tend
to avoid whitespace when formatting your own code (e.g. [0]) so
if '{}{}' was
allowed (in addition to '()()') your code would look even more
cryptic
(at least to me) :P
The Phobos style guide, which also mostly matches my personal
preference
is to write code like this:
T sqrt(T)(T n)
if (isNumeric!(Unqual!T) || is(Unqual!T == BigInt))
in
{
assert(n >= 0);
}
out (result)
{
assert(result * result == n);
}
body
{
//Implementation
}
If the block is short I sometimes write it like so:
T sqrt(T)(T n)
if (isNumeric!(Unqual!T) || is(Unqual!T == BigInt))
in { assert(n >= 0); }
out (result) { assert(result * result == n); }
body
{
//Implementation
}
With removal of 'body', the code would look like so:
T sqrt(T)(T n)
if (isNumeric!(Unqual!T) || is(Unqual!T == BigInt))
in { assert(n >= 0); }
out (result) { assert(result * result == n); }
{
//Implementation
}
Which I actually think looks good.
A small improvement, in addition to omitting 'body' would be to
allow
omitting the braces if the 'in' or 'out' blocks contain only a
single
statement (similar to 'if', 'foreach', etc.) and to add a similar
syntax sugar alternative for template constraints:
T sqrt(T)(T n)
if Unqual!T U: isNumeric!U || is(U == BigInt)
in n >= 0
out (result) result * result == n
{
//Implementation
}
[0]:
https://github.com/tgehr/d-compiler/blob/175ccb81d6f35feb4fcf3050180ccf6357b4fa51/semantic.d#L845
https://github.com/tgehr/d-compiler/blob/175ccb81d6f35feb4fcf3050180ccf6357b4fa51/parser.d#L122
https://github.com/tgehr/d-compiler/blob/175ccb81d6f35feb4fcf3050180ccf6357b4fa51/semantic.d#L131
More information about the Digitalmars-d
mailing list