digitalmars.D - Parenthesis around if/for/while condition is not necessary
- aedt (9/9) Jun 22 2018 for line in stdin.lines() {}
- Jonathan M Davis (34/43) Jun 22 2018 I expect that it's in keeping with why D also has semicolons. The added
- Dennis (30/39) Jun 24 2018 I don't see why allowing one to omit the parens makes porting C
- Jonathan M Davis (22/35) Jun 24 2018 It makes it harder if the language does not have parens on if statements...
- aliak (11/43) Jun 24 2018 FWIW, a lot of people I try and get in to D complain about the
- Timoses (7/10) Jun 24 2018 if ("key" !in dict) {...}
- Nick Treleaven (7/12) Jul 01 2018 Yes, but you might make a mistake, and sometimes it makes more
- user1234 (6/15) Jun 22 2018 There is this case that requires parens:
- aedt (6/27) Jun 22 2018 Same thing as the following"
- user1234 (6/36) Jun 22 2018 I agree that this would be in adequation with certain stuff of
- Basile B. (7/46) Jun 22 2018 Maybe but this is a simple parser thing. For example after
- Basile B. (16/63) Jun 24 2018 FYI this works fine, as expected it's just some small parser
- aliak (16/59) Jun 24 2018 Wow nice, that was quick, would it be much more to make it so
- Basile B. (2/55) Jun 25 2018 It's in the commit.
- Timon Gehr (2/8) Jul 04 2018 if (a+b)*c == d { ... }
- Nick Treleaven (7/8) Jul 05 2018 Error: found `{` when expecting `;` following statement
- Basile B. (3/12) Jul 05 2018 right, maybe logic to apply here is : if the expression parses
- Basile B. (4/17) Jul 05 2018 Actually with the change the example doesn't parse and without it
- FeepingCreature (2/8) Jul 04 2018 Why not just require either parens or brackets?
- Nick Sabalausky (Abscissa) (11/25) Jun 22 2018 Mainly because of D's C-family lineage. D was designed to use syntax
- Jacob Carlborg (8/16) Jun 23 2018 For the parentheses to be optional I think the curly brace need to be
- user1234 (3/26) Jun 23 2018 I wouldn't like the new line constraint. Forcing Curly braces is
- =?UTF-8?Q?Tobias=20M=C3=BCller?= (4/7) Jun 23 2018 AFAIK the if and else branches in Rust always have to be enclosed in cur...
- Jacob Carlborg (8/11) Jun 24 2018 There's an ambiguity between the condition and the body. There needs to
- Basile B. (5/15) Jun 24 2018 Yeah, as pointed out at the beginning
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.
Jun 22 2018
On Saturday, June 23, 2018 01:27:30 aedt via Digitalmars-d 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.I expect that it's in keeping with why D also has semicolons. The added redundancy and separation between statements makes it easier for the compiler to give intelligent error messages and makes it easier for the reader of the code to see what's going on. This is particularly true for parens when you consider that single statement bodies without braces are allowed for if statements and loops. Not having parens in such cases would be akin to not having a semicolon at the end of a statement, and in the case of the for loop, it actually creates an ambiguity problem. When does the statement in the third portion end and the statement in the body begin? Another consideration is that it's an unnecessary difference from C/C++ code. In general, C code is supposed to be either valid D code or not compile in order to making porting it easier. Getting rid of the parens wouldn't break that, but it _would_ make it so that it's more work to port C code to D when doing so is supposed to be straightforward in most cases. And of course, the counter question to why the parens shouldn't be removed would be the question of why they should be. What about having parens makes the code worse? Many of us would consider the code easier to read with parens. Ultimately, by having these delimiters, the intent of the code tends to be clearer when mistakes are made, and the compiler can give better error messages, because it's easier for the compiler to accurately guess what the programmer intended. Yes, on some level, it's a subjective design decision, but it's also not at all the true that programmers in general are going to agree that removing stuff like parens or semicolons from the language is a good idea. Some will and some won't. And D follows very much in the tradition of C and C++ with decisions like this. Syntax was changed from those languages when the syntax actually caused problems (e.g. C function pointers tend to be problematic, so D has a different syntax for them), but if the C/C++ syntax was not considered to be a problem, it was largely left as-is in D. That makes code porting easier, and it makes it easier for programmers to transition to the language. - Jonathan M Davis
Jun 22 2018
On Saturday, 23 June 2018 at 02:14:04 UTC, Jonathan M Davis wrote:In general, C code is supposed to be either valid D code or not compile in order to making porting it easier. Getting rid of the parens wouldn't break that, but it _would_ make it so that it's more work to port C code to D when doing so is supposed to be straightforward in most cases. And of course, the counter question to why the parens shouldn't be removed would be the question of why they should be. What about having parens makes the code worse? Many of us would consider the code easier to read with parens.I don't see why allowing one to omit the parens makes porting C code harder. The fact that D allows `printf = "hello world";` doesn't mean you have to write it like that, you can still use the C notation. The same applies to parens. I would be in favor for allowing this. It's not that I encourage omitting them, it's similar to curly braces around the statement: You want them most of the time, but in certain scenarios you like to be able to leave them out. In particular: if (!("key" in dict)) {...} if (!(flags & 0x40)) {...} These are annoying to type and read. There are more than 100 instances of this in the dmd source code. Aren't these just much nicer? :) if !("key" in dict) {...} if !(flags & 0x40) {...} It gets worse as expressions get larger. Parens may be easy to read around small expressions, but can you tell quickly whether the parens below are balanced? if (!(t1.ty == Tarray && t2.ty == Tarray && needsDirectEq(t1, t2)) How about this one? if (!(i1 && i2 && (i1.mod == i2.mod || (!i1.parent.isImport() && !i2.parent.isImport() && i1.ident.equals(i2.ident))))) The compiler will easily output 5+ error messages pointing to the wrong place when a closing paren is missing ("missing { ... } for function literal", "unrecognized declaration"). So I'm not convinced that error message quality is at stake here. To avoid ambiguity of where the expression ends and body starts, it can be enforced that either () around the expression or {} around the statement must be present.
Jun 24 2018
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: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 DavisIn general, C code is supposed to be either valid D code or not compile in order to making porting it easier. Getting rid of the parens wouldn't break that, but it _would_ make it so that it's more work to port C code to D when doing so is supposed to be straightforward in most cases. And of course, the counter question to why the parens shouldn't be removed would be the question of why they should be. What about having parens makes the code worse? Many of us would consider the code easier to read with parens.I don't see why allowing one to omit the parens makes porting C code harder.
Jun 24 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: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, - AliOn Saturday, 23 June 2018 at 02:14:04 UTC, Jonathan M Davis wrote: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[...]I don't see why allowing one to omit the parens makes porting C code harder.
Jun 24 2018
On Sunday, 24 June 2018 at 22:03:13 UTC, Dennis wrote:if (!("key" in dict)) {...}if ("key" !in dict) {...} At least that one has a shorter form. The others may be rewritten to not have a leading "!" as well, e.g.if (!(t1.ty == Tarray && t2.ty == Tarray && needsDirectEq(t1, t2))if (t1.ty != Tarray || t2.ty != Tarray || ...) Plus, for counting brackets a text editor that highlights enclosing opposite brackets really helps.
Jun 24 2018
On Sunday, 24 June 2018 at 23:40:56 UTC, Timoses wrote:The others may be rewritten to not have a leading "!" as well, e.g.Yes, but you might make a mistake, and sometimes it makes more intuitive sense to read it in a non-minimized form. This type of change is also much harder to review. Consider why the change got checked into dmd, without it being minimized at the time or in a later pull.if (!(t1.ty == Tarray && t2.ty == Tarray && needsDirectEq(t1, t2))if (t1.ty != Tarray || t2.ty != Tarray || ...)
Jul 01 2018
On Sunday, 1 July 2018 at 12:02:03 UTC, Nick Treleaven wrote:On Sunday, 24 June 2018 at 23:40:56 UTC, Timoses wrote:and it wouldn't be hard for D to support it too: https://github.com/dlang/dmd/pull/8440 It just requires someone to step up and write the DIP.The others may be rewritten to not have a leading "!" as well, e.g.Yes, but you might make a mistake, and sometimes it makes more intuitive sense to read it in a non-minimized form. This type of change is also much harder to review. Consider why the change got checked into dmd, without it being minimized at the time or in a later pull.if (!(t1.ty == Tarray && t2.ty == Tarray && needsDirectEq(t1, t2))if (t1.ty != Tarray || t2.ty != Tarray || ...)
Jul 02 2018
On Monday, 2 July 2018 at 20:28:06 UTC, Seb wrote:On Sunday, 1 July 2018 at 12:02:03 UTC, Nick Treleaven wrote:Since ! is used to pass template params... I'd rather use it for parameterized keywords in the same way, for instance: if!likely(...) if!unlikely(...) It would standardize the existing practice of "__builtin_expect". Also it you really wanted, you could add something like: if!not(...)On Sunday, 24 June 2018 at 23:40:56 UTC, Timoses wrote:and it wouldn't be hard for D to support it too: https://github.com/dlang/dmd/pull/8440 It just requires someone to step up and write the DIP.The others may be rewritten to not have a leading "!" as well, e.g.Yes, but you might make a mistake, and sometimes it makes more intuitive sense to read it in a non-minimized form. This type of change is also much harder to review. Consider why the change got checked into dmd, without it being minimized at the time or in a later pull.if (!(t1.ty == Tarray && t2.ty == Tarray && needsDirectEq(t1, t2))if (t1.ty != Tarray || t2.ty != Tarray || ...)
Jul 04 2018
On Saturday, 23 June 2018 at 01:27:30 UTC, 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.There is this case that requires parens: if a && b c; Is there a missing && or not ? It seems obvious for a human but compiler parsers are "apparatchiks", i.e rules are rules. That being said this would work by allowing parens for disambiguation.
Jun 22 2018
On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote:On Saturday, 23 June 2018 at 01:27:30 UTC, aedt wrote:Same thing as the following" return a && b; I'm not saying to drop parens completely, I'm saying why is it not optional. D seems to have no problem with x.to!string or std.linesfor 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.There is this case that requires parens: if a && b c; Is there a missing && or not ? It seems obvious for a human but compiler parsers are "apparatchiks", i.e rules are rules. That being said this would work by allowing parens for disambiguation.
Jun 22 2018
On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote:On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote:I agree that this would be in adequation with certain stuff of the D syntax, such as parens-less single template parameter. Someone has to make a DIP for this otherwise we're good for one of this sterile NG discussion leading to nothing, i.e intellectual mast... well guess the word.On Saturday, 23 June 2018 at 01:27:30 UTC, aedt wrote:Same thing as the following" return a && b; I'm not saying to drop parens completely, I'm saying why is it not optional. D seems to have no problem with x.to!string or std.linesfor 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.There is this case that requires parens: if a && b c; Is there a missing && or not ? It seems obvious for a human but compiler parsers are "apparatchiks", i.e rules are rules. That being said this would work by allowing parens for disambiguation.
Jun 22 2018
On Saturday, 23 June 2018 at 06:18:53 UTC, user1234 wrote:On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote:Maybe but this is a simple parser thing. For example after reading the discussion here i have tested the idea in my toy programming language (https://github.com/BBasile/styx/commit/83c96d8a789aa82f9bed2 4ab342ffc4aed4fd88) and i believe that for D this would be as simple ( < 20 SLOC, w/o the tests).On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote:I agree that this would be in adequation with certain stuff of the D syntax, such as parens-less single template parameter. Someone has to make a DIP for thisOn Saturday, 23 June 2018 at 01:27:30 UTC, aedt wrote:Same thing as the following" return a && b; I'm not saying to drop parens completely, I'm saying why is it not optional. D seems to have no problem with x.to!string or std.linesfor 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.There is this case that requires parens: if a && b c; Is there a missing && or not ? It seems obvious for a human but compiler parsers are "apparatchiks", i.e rules are rules. That being said this would work by allowing parens for disambiguation.otherwise we're good for one of this sterile NG discussion leading to nothing, i.e intellectual mast... well guess the word.I'm tempted to try this in DMDFE. Change is simple enough so that if it get rejected no much time is lost.
Jun 22 2018
On Saturday, 23 June 2018 at 06:24:29 UTC, Basile B. wrote:On Saturday, 23 June 2018 at 06:18:53 UTC, user1234 wrote:FYI this works fine, as expected it's just some small parser changes. I didn't touch to for and foreach for now. I think that SwitchStatement is a candidate too. https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3d However note that there's a nice thing with the phobos style that won't be that nice anymore: if (condition) action(); ----^ if condition) action(); ---^ ----^ It's not nicely aligned anymore !On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote:Maybe but this is a simple parser thing. For example after reading the discussion here i have tested the idea in my toy programming language (https://github.com/BBasile/styx/commit/83c96d8a789aa82f9bed2 4ab342ffc4aed4fd88) and i believe that for D this would be as simple ( < 20 SLOC, w/o the tests).On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote:I agree that this would be in adequation with certain stuff of the D syntax, such as parens-less single template parameter. Someone has to make a DIP for thisOn Saturday, 23 June 2018 at 01:27:30 UTC, aedt wrote:Same thing as the following" return a && b; I'm not saying to drop parens completely, I'm saying why is it not optional. D seems to have no problem with x.to!string or std.linesfor 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.There is this case that requires parens: if a && b c; Is there a missing && or not ? It seems obvious for a human but compiler parsers are "apparatchiks", i.e rules are rules. That being said this would work by allowing parens for disambiguation.otherwise we're good for one of this sterile NG discussion leading to nothing, i.e intellectual mast... well guess the word.I'm tempted to try this in DMDFE. Change is simple enough so that if it get rejected no much time is lost.
Jun 24 2018
On Sunday, 24 June 2018 at 11:27:12 UTC, Basile B. wrote:On Saturday, 23 June 2018 at 06:24:29 UTC, Basile B. wrote:Wow nice, that was quick, would it be much more to make it so that braces are required with if statements that do not start with an open paren? Then you avoid the ambiguity I guess ... It'd be awesome if D allowed it optionally though. Not that I have a strong opinion here but I have found that being able to omit the parens makes the code look A Lot cleaner. And forcing braces I've also come to apprecaite with a bonus of avoiding this bug: if (a) b; c; Though forcing braces in D may make phobos quite sparse since it uses allman braces so we'll get 4 line if statements everywhere :p Cheers, - AliOn Saturday, 23 June 2018 at 06:18:53 UTC, user1234 wrote:FYI this works fine, as expected it's just some small parser changes. I didn't touch to for and foreach for now. I think that SwitchStatement is a candidate too. https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3d However note that there's a nice thing with the phobos style that won't be that nice anymore: if (condition) action(); ----^ if condition) action(); ---^ ----^ It's not nicely aligned anymore !On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote:Maybe but this is a simple parser thing. For example after reading the discussion here i have tested the idea in my toy programming language (https://github.com/BBasile/styx/commit/83c96d8a789aa82f9bed2 4ab342ffc4aed4fd88) and i believe that for D this would be as simple ( < 20 SLOC, w/o the tests).On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote:I agree that this would be in adequation with certain stuff of the D syntax, such as parens-less single template parameter. Someone has to make a DIP for this[...]Same thing as the following" return a && b; I'm not saying to drop parens completely, I'm saying why is it not optional. D seems to have no problem with x.to!string or std.linesotherwise we're good for one of this sterile NG discussion leading to nothing, i.e intellectual mast... well guess the word.I'm tempted to try this in DMDFE. Change is simple enough so that if it get rejected no much time is lost.
Jun 24 2018
On Sunday, 24 June 2018 at 23:08:15 UTC, aliak wrote:On Sunday, 24 June 2018 at 11:27:12 UTC, Basile B. wrote:It's in the commit.On Saturday, 23 June 2018 at 06:24:29 UTC, Basile B. wrote:Wow nice, that was quick, would it be much more to make it so that braces are required with if statements that do not start with an open paren?On Saturday, 23 June 2018 at 06:18:53 UTC, user1234 wrote:FYI this works fine, as expected it's just some small parser changes. I didn't touch to for and foreach for now. I think that SwitchStatement is a candidate too. https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3d However note that there's a nice thing with the phobos style that won't be that nice anymore: if (condition) action(); ----^ if condition) action(); ---^ ----^ It's not nicely aligned anymore !On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote:Maybe but this is a simple parser thing. For example after reading the discussion here i have tested the idea in my toy programming language (https://github.com/BBasile/styx/commit/83c96d8a789aa82f9bed2 4ab342ffc4aed4fd88) and i believe that for D this would be as simple ( < 20 SLOC, w/o the tests).On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote:I agree that this would be in adequation with certain stuff of the D syntax, such as parens-less single template parameter. Someone has to make a DIP for this[...]Same thing as the following" return a && b; I'm not saying to drop parens completely, I'm saying why is it not optional. D seems to have no problem with x.to!string or std.linesotherwise we're good for one of this sterile NG discussion leading to nothing, i.e intellectual mast... well guess the word.I'm tempted to try this in DMDFE. Change is simple enough so that if it get rejected no much time is lost.
Jun 25 2018
On Monday, 25 June 2018 at 10:36:46 UTC, Basile B. wrote:On Sunday, 24 June 2018 at 23:08:15 UTC, aliak wrote:https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3d#diff-cd066d37445cac534313c0137c2d4bbeR5599On Sunday, 24 June 2018 at 11:27:12 UTC, Basile B. wrote:It's in the commit.On Saturday, 23 June 2018 at 06:24:29 UTC, Basile B. wrote:Wow nice, that was quick, would it be much more to make it so that braces are required with if statements that do not start with an open paren?On Saturday, 23 June 2018 at 06:18:53 UTC, user1234 wrote:FYI this works fine, as expected it's just some small parser changes. I didn't touch to for and foreach for now. I think that SwitchStatement is a candidate too. https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3d However note that there's a nice thing with the phobos style that won't be that nice anymore: if (condition) action(); ----^ if condition) action(); ---^ ----^ It's not nicely aligned anymore !On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote:Maybe but this is a simple parser thing. For example after reading the discussion here i have tested the idea in my toy programming language (https://github.com/BBasile/styx/commit/83c96d8a789aa82f9bed2 4ab342ffc4aed4fd88) and i believe that for D this would be as simple ( < 20 SLOC, w/o the tests).On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote:I agree that this would be in adequation with certain stuff of the D syntax, such as parens-less single template parameter. Someone has to make a DIP for this[...]Same thing as the following" return a && b; I'm not saying to drop parens completely, I'm saying why is it not optional. D seems to have no problem with x.to!string or std.linesotherwise we're good for one of this sterile NG discussion leading to nothing, i.e intellectual mast... well guess the word.I'm tempted to try this in DMDFE. Change is simple enough so that if it get rejected no much time is lost.
Jun 25 2018
On Monday, 25 June 2018 at 10:38:49 UTC, Basile B. wrote:On Monday, 25 June 2018 at 10:36:46 UTC, Basile B. wrote:Indeed! Totally missed that! PR Itttt!!! :DOn Sunday, 24 June 2018 at 23:08:15 UTC, aliak wrote:https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3d#diff-cd066d37445cac534313c0137c2d4bbeR5599Wow nice, that was quick, would it be much more to make it so that braces are required with if statements that do not start with an open paren?It's in the commit.
Jun 25 2018
On Monday, 25 June 2018 at 12:19:15 UTC, aliak wrote:On Monday, 25 June 2018 at 10:38:49 UTC, Basile B. wrote:What i would make if i was a new comer. Language changes must be formally specified with a DIP. I don't especially want to write it but if one of the of the paren-less statements 'partisan' wants to then you can count on me if at a time an implementation is required (even as demo in a first time).On Monday, 25 June 2018 at 10:36:46 UTC, Basile B. wrote:Indeed! Totally missed that! PR Itttt!!! :DOn Sunday, 24 June 2018 at 23:08:15 UTC, aliak wrote:https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3d#diff-cd066d37445cac534313c0137c2d4bbeR5599Wow nice, that was quick, would it be much more to make it so that braces are required with if statements that do not start with an open paren?It's in the commit.
Jul 02 2018
On 24.06.2018 13:27, Basile B. wrote:FYI this works fine, as expected it's just some small parser changes. I didn't touch to for and foreach for now. I think that SwitchStatement is a candidate too. https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3dif (a+b)*c == d { ... }
Jul 04 2018
On Wednesday, 4 July 2018 at 14:37:49 UTC, Timon Gehr wrote:if (a+b)*c == d { ... }Error: found `{` when expecting `;` following statement Adding the semi-colon, `*c == d;` would likely cause: Error: `*c == d` has no effect Also multiplying (a+b) by a pointer is illegal, and c is probably a pointer if it can be dereferenced. In theory a UDT could define opUnary!"*" and opBinary!"*", is that likely?
Jul 05 2018
On Wednesday, 4 July 2018 at 14:37:49 UTC, Timon Gehr wrote:On 24.06.2018 13:27, Basile B. wrote:right, maybe logic to apply here is : if the expression parses and no closing paren is found then it's not nececessary.FYI this works fine, as expected it's just some small parser changes. I didn't touch to for and foreach for now. I think that SwitchStatement is a candidate too. https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3dif (a+b)*c == d { ... }
Jul 05 2018
On Thursday, 5 July 2018 at 09:45:44 UTC, Basile B. wrote:On Wednesday, 4 July 2018 at 14:37:49 UTC, Timon Gehr wrote:Actually with the change the example doesn't parse and without it didn't either. The program meaning is not altered so it's fine.On 24.06.2018 13:27, Basile B. wrote:right, maybe logic to apply here is : if the expression parses and no closing paren is found then it's not nececessary.FYI this works fine, as expected it's just some small parser changes. I didn't touch to for and foreach for now. I think that SwitchStatement is a candidate too. https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3dif (a+b)*c == d { ... }
Jul 05 2018
On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote:There is this case that requires parens: if a && b c; Is there a missing && or not ? It seems obvious for a human but compiler parsers are "apparatchiks", i.e rules are rules. That being said this would work by allowing parens for disambiguation.Why not just require either parens or brackets?
Jul 04 2018
On 06/22/2018 09:27 PM, 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.Mainly because of D's C-family lineage. D was designed to use syntax that would be familiar to programmers of the other popular C-derived in a C-ish (more or less) language was largely popularized by Go, but at the time, Go didn't exist yet. Whatever the reasons, I'm personally glad it worked out this way: I find it very difficult to visually parse loops and conditionals that omit the parens. Without them, there just isn't enough visual "landmarks" for my brain's visual center to lock-on and pattern-recognize a standard loop or conditional.
Jun 22 2018
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. -- /Jacob Carlborg
Jun 23 2018
On Saturday, 23 June 2018 at 08:07:23 UTC, Jacob Carlborg wrote:On 2018-06-23 03:27, aedt wrote:I wouldn't like the new line constraint. Forcing Curly braces is nice, logic and natural imo.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.
Jun 23 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:Just like spaces line endings are not a thing in D anyway.On 2018-06-23 03:27, aedt wrote:I wouldn't like the new line constraint. Forcing Curly braces is nice, logic and natural imo.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.
Jun 23 2018
On Saturday, 23 June 2018 at 09:19:45 UTC, user1234 wrote:...Forcing Curly braces is nice, logic and natural imo.The operator brackets themselves are a separate construction. In addition, the more structured the code, the less they are needed. In my code, most of the loops and branches contain one operator, so forcing the сurly braces would simply add a large amount of syntactic noise.
Jun 23 2018
aedt <adnansignsup gmail.com> wrote:Modern languages have already dropped this requirement (i.e. Rust, Nim) and I don't see any reason not to do so.AFAIK the if and else branches in Rust always have to be enclosed in curly braces because of this. I don't remember the exact ambiguity though.
Jun 23 2018
On 2018-06-23 14:34, Tobias Müller wrote:AFAIK the if and else branches in Rust always have to be enclosed in curly braces because of this. I don't remember the exact ambiguity though.There's an ambiguity between the condition and the body. There needs to be some kind of symbol to separate the two. In D, that's the closing parenthesis (technically the opening parenthesis is not necessary but unbalanced parentheses look weird for humans). In Rust it's the opening curly brace. -- /Jacob Carlborg
Jun 24 2018
On Sunday, 24 June 2018 at 08:30:28 UTC, Jacob Carlborg wrote:On 2018-06-23 14:34, Tobias Müller wrote:Yeah, as pointed out at the beginning https://forum.dlang.org/post/gwxrvrzgycnxwzzszkbr forum.dlang.org Despite of the ugliness of the construct the main issue is that a binary or a relational operator could be missing in this case.AFAIK the if and else branches in Rust always have to be enclosed in curly braces because of this. I don't remember the exact ambiguity though.There's an ambiguity between the condition and the body. There needs to be some kind of symbol to separate the two. In D, that's the closing parenthesis (technically the opening parenthesis is not necessary but unbalanced parentheses look weird for humans). In Rust it's the opening curly brace.
Jun 24 2018