Parenthesis around if/for/while condition is not necessary

aliak something at something.com
Sun Jun 24 23:13:09 UTC 2018


On Sunday, 24 June 2018 at 22:25:43 UTC, Jonathan M Davis wrote:
> On Sunday, June 24, 2018 22:03:13 Dennis via Digitalmars-d 
> wrote:
>> On Saturday, 23 June 2018 at 02:14:04 UTC, Jonathan M Davis 
>> wrote:
>> > [...]
>>
>> I don't see why allowing one to omit the parens makes porting 
>> C code harder.
>
> It makes it harder if the language does not have parens on if 
> statements, while loops, etc., because then you have to remove 
> them from all of the code that you're porting. Having them be 
> optional shouldn't make porting harder. The OP's post said 
> nothing about making them optional, just complained that they 
> were in the language, so I posted based on the assumption that 
> they were arguing for their removal from the language. However, 
> optional parens would make it more confusing when reading code 
> (since then you have to figure out whether parens go with the 
> if or the expression in the conditional), and it's the sort of 
> thing that's just going to start style wars.
>
> Also, usually, I hear about how folks _like_ D's syntax and 
> find it easy to learn, whereas many complain about the syntax 
> in languages such as Rust (it's my understanding that folks 
> tend to like Rust in spite of its syntax, not because of it). 
> So, it seems a bit odd to try and emulate them.
>
> Regardless, personally, I don't want to have to deal with 
> reading code that omits parens on if statements and loops. It 
> just makes the language less consistent and makes it more work 
> to read code (as well as opening the door for yet more 
> arguments about the style guidelines on projects). Obviously, 
> others can disagree, but I'd vote strongly against any attempt 
> to change D in this regard.
>
> - Jonathan M Davis

FWIW, a lot of people I try and get in to D complain about the 
template syntax. "What're all those exclamation marks 
everywhere??!!" - Every. Single. Time. And as soon as you see 
__traits code anywhere you can say good bye to any aesthetic 
pleasures. There're things in every language you just have to get 
used to looking at and at some point things just start to look 
nice. After a while I didn't even think objective-c bracket hell 
was too bad :p

Cheers,
- Ali


More information about the Digitalmars-d mailing list