Parenthesis around if/for/while condition is not necessary

user1234 user1234 at 12.nl
Sat Jun 23 10:44:38 UTC 2018


On Saturday, 23 June 2018 at 09:19:45 UTC, user1234 wrote:
> On Saturday, 23 June 2018 at 08:07:23 UTC, Jacob Carlborg wrote:
>> On 2018-06-23 03:27, aedt wrote:
>>> for line in stdin.lines() {}
>>>
>>> if condition {}
>>>
>>> while condition {}
>>>
>>> for init; condition; op {}
>>>
>>>
>>> What's the rationale of keeping the requirement that the 
>>> condition of
>>> if/for/while must be wrapped with a parenthesis (other than 
>>> keeping
>>> parser simple)? Modern languages have already dropped this 
>>> requirement
>>> (i.e. Rust, Nim) and I don't see any reason not to do so.
>>
>> For the parentheses to be optional I think the curly brace 
>> need to be mandatory, or perhaps force a newline after the 
>> condition. I don't see how this would be any better. You're 
>> trading one set of required punctuational characters for 
>> another set. This would also take D one step further away from 
>> the C family of languages.
>
> I wouldn't like the new line constraint. Forcing Curly braces 
> is nice, logic and natural imo.

Just like spaces line endings are not a thing in D anyway.


More information about the Digitalmars-d mailing list