September 23, 2010 [Issue 4375] Require explicit braces when 'else' is ambiguous | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4375 --- Comment #10 from Jonathan M Davis <jmdavisProg@gmx.com> 2010-09-23 13:00:50 PDT --- Except that this case is a classic case in computer programming with a clear and standard solution. The grammar is totally unambiguous. I can't see Walter ever agreeing to make it an error. No other language that I'm aware of does. A warning makes some sense. An error does not. Granted, Walter doesn't like warnings, but that doesn't mean that there's no way that he's going to add it, and there's always the possibility that another D compiler down the road would flag it as a warning. Just because Walter wouldn't want to make it a warning in dmd doesn't mean that it should become an error. If it's a question of error or nothing, I'm strongly behind nothing, and my guess is that Walter will be as well. I'm fine with it becoming a warning, but an error is too strong. The language is quite clear on the matter. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 23, 2010 [Issue 4375] Require explicit braces when 'else' is ambiguous | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4375 --- Comment #11 from bearophile_hugs@eml.cc 2010-09-23 13:11:30 PDT --- Jonathan M Davis: >The grammar is totally unambiguous.< For a computer. But people aren't that precise. The syntax of a computer language is not designed for the computer, it's designed to be an interface for the very bug-prone apes that use the computer. >I can't see Walter ever agreeing to make it an error.< In D there are several precedents, this is a bug in D only: for (i = 0; i < 10; i++); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 23, 2010 [Issue 4375] Require explicit braces when 'else' is ambiguous | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4375 --- Comment #12 from Stewart Gordon <smjg@iname.com> 2010-09-23 13:23:32 PDT --- (In reply to comment #11) > In D there are several precedents, this is a bug in D only: > for (i = 0; i < 10; i++); It isn't a bug, it's illegal code. A bug is something different. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 11, 2010 [Issue 4375] Require explicit braces when 'else' is ambiguous | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4375 --- Comment #13 from bearophile_hugs@eml.cc 2010-10-11 13:09:16 PDT --- Just for reference this is what Wikipedia says about the Ada language: Conditional statements are closed with "end if", avoiding a dangling else that could pair with the wrong nested if-expression in other languages. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 07, 2010 [Issue 4375] Require explicit braces when 'else' is ambiguous | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4375 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bugzilla@digitalmars.com --- Comment #14 from Walter Bright <bugzilla@digitalmars.com> 2010-11-07 14:28:11 PST --- Stewart's right in that this change can be effected by changing the grammar. You can get into all kinds of confusion by perversely indenting the source code, this particular one isn't special and so doesn't warrant special treatment. What I think would be of significant value is to create a D source code formatter that will properly indent the code based on the grammar. I'd love such a tool, and would use it (for example) as a filter on all D source code checkins. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 08, 2010 [Issue 4375] Require explicit braces when 'else' is ambiguous | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4375 --- Comment #15 from bearophile_hugs@eml.cc 2010-11-08 04:00:05 PST --- (In reply to comment #14) > Stewart's right in that this change can be effected by changing the grammar. Good, the grammar may just require braces in this case. This is a good enough solution. > You can get into all kinds of confusion by perversely indenting the source code, this particular one isn't special and so doesn't warrant special treatment. From what I have seen this particular indentation is a common enough bug, while other indentations aren't a common enough source of bugs. But you are right, there are other wrong kinds of indentations that may be sources of bugs that will enjoy specific warnings (example: unexpected negative indents warning). > What I think would be of significant value is to create a D source code formatter that will properly indent the code based on the grammar. I'd love such a tool, and would use it (for example) as a filter on all D source code checkins. The purpose of a modern IDE is to contain few hundred functionalities like this one. Using a different tool for those functionalities is not practical nor is what most modern programmers look for. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 08, 2010 [Issue 4375] Require explicit braces when 'else' is ambiguous | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4375 --- Comment #16 from bearophile_hugs@eml.cc 2010-11-08 04:06:22 PST --- (In reply to comment #14) > You can get into all kinds of confusion by perversely indenting the source code, this particular one isn't special and so doesn't warrant special treatment. This particular problem caused by indenting has even a name, "dangling else problem". When a problem gains a name it means it's not something equal to other things, it's different enough. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 04, 2011 [Issue 4375] Require explicit braces when 'else' is ambiguous | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4375 --- Comment #17 from bearophile_hugs@eml.cc 2011-08-03 18:59:30 PDT --- I've being hit by a "dangling else" bug in D, traslating this Python code: def foo(sol): global best if is_solution(sol[-1]): if best or len(sol) < len(best): best = list(sol) else: for next in alternatives(sol[-1]): if next not in sol: foo(sol + [next]) to the wrong D code: void foo(Pair[] sol) { if (isSolution(sol[$-1])) if (!best.length || sol.length < best.length) best = sol.dup; else foreach (next; alternatives(sol[$-1])) if (!canFind(sol, next)) foo(sol ~ [next]); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 21, 2011 [Issue 4375] Require explicit braces when 'else' is ambiguous | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4375 Nick Sabalausky <cbkbbejeap@mailinator.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |cbkbbejeap@mailinator.com --- Comment #18 from Nick Sabalausky <cbkbbejeap@mailinator.com> 2011-08-21 14:17:14 PDT --- "You can get into all kinds of confusion by perversely indenting the source code, this particular one isn't special and so doesn't warrant special treatment." I disagree with this assessment. The whitespace is not the core problem here. The core problem is that the construct "if(cond) stmt; if(cond) stmt; else..." (with no braces) is generally confusing for people. The whitespace merely makes for a more illustrative example. To demonstrate, the following code is perfectly valid and works as intended, but despite that, it would still make a lot of programmers very nervous anyway: if(x == 17) if(useFoo) foo(); else bar(); While it's true there's plenty of general confusion that can be caused by misleading whitespace, that's really a separate class of issues. It's a class of issues that can certainly aggravate the "if if else" matter, but that's just because, like you said, they can aggravate any situation. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 23, 2011 [Issue 4375] Require explicit braces when 'else' is ambiguous | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4375 --- Comment #19 from bearophile_hugs@eml.cc 2011-08-23 00:03:56 PDT --- See also: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=142984 http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=142985 http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=142993 Implementation ideas: http://code.google.com/p/copute/issues/detail?id=21 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation