DIP 1003 Formal Review
via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 14 06:24:52 PDT 2017
On Sunday, 14 May 2017 at 13:04:12 UTC, Steven Schveighoffer
wrote:
> On 5/13/17 6:07 PM, Petar Kirov [ZombineDev] wrote:
>> On Saturday, 13 May 2017 at 18:07:57 UTC, Timon Gehr wrote:
>>> On 13.05.2017 16:30, Petar Kirov [ZombineDev] wrote:
>>>> On Saturday, 13 May 2017 at 10:27:25 UTC, Timon Gehr wrote:
>>>>> [...]
>>>>
>>>> Hmm, I guess it depends on how you format your code.
>>>
>>> No, it does not. This was a point about the grammar.
>>>
>>> How would you feel about:
>>>
>>> if(condition){ then(); }
>>> { otherwise(); }
>>
>> I don't see any problem, in fact this is valid code even today
>> - both in
>> C++ and D.
>> And my case still stands - if you were to format the code like
>> this:
>>
>> if (condition)
>> {
>> then();
>> }
>>
>> {
>> otherwise();
>> }
>>
>> then the intent would be more obvious. At least in C++ using a
>> plain
>> scope { }
>> is common idiom used to explicitly limit the lifetime of RAII
>> objects
>> declared
>> within it.
>
> There is a huge difference. if() {} else {} is semantically
> completely different than if() {} {}
Obviously. I was just referring to the fact 'if (expr) {} {}' is
already valid today and I don't think it confuses anyone with 'if
(expr) {} else {}', *if code is formatted and/or commented
properly*.
> Currently, we already allow omitting body when in/out aren't
> present:
>
> void foo()
> {
> }
>
> is equivalent to
>
> void foo()
> body
> {
> }
>
> I think really, option 1 is both the easiest and least
> disruptive. I'm OK with option 3, but it sure seems like an
> unnecessary breakage.
>
> -Steve
By making body optional and a contextual keyword there should be
no breaking changes (except for obscure code like `static assert
(!__traits(compiles, { mixin ("int body;"); }))` :D).
More information about the Digitalmars-d
mailing list