Re: Optional braces

2011-08-26 Thread bearophile
Walter: Here you are essentially asking for a more global view of the D design, to see if we are using too much plastic surgery. To have such global view we need to look at many unrelated things. So sorry if this looks like a lot of meat on the fire, there is no other way. We've already put

Re: Optional braces

2011-08-26 Thread bearophile
And there are few more special cases where I'd like to see changes/improvements on (there are other improvements that I'd like to see, but they aren't special cases): 3878 Arguments and attributes with the same name 4407 Catch wrong argument-attribute assignments in methods 5187

Re: Optional braces

2011-08-26 Thread Marco Leise
Am 26.08.2011, 11:32 Uhr, schrieb bearophile bearophileh...@lycos.com: There is one more special case that we plan to disallow, that's not in DMD yet: 5409 Disallow (!x y) http://d.puremagic.com/issues/show_bug.cgi?id=5409 Is (!x y) an issue or is it rather people omitting spaces in

Re: Optional braces

2011-08-26 Thread bearophile
Marco Leise: Is (!x y) an issue or is it rather people omitting spaces in their code !xy ? This topic was already discussed in past, in two threads, this one of them: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.Darticle_id=135741 The Coccinelle tool has found a

Re: Optional braces

2011-08-26 Thread Marco Leise
Am 26.08.2011, 13:10 Uhr, schrieb bearophile bearophileh...@lycos.com: Marco Leise: Is (!x y) an issue or is it rather people omitting spaces in their code !xy ? This topic was already discussed in past, in two threads, this one of them:

Re: Optional braces

2011-08-26 Thread Andrei Alexandrescu
On 8/25/11 9:13 PM, Walter Bright wrote: On 8/25/2011 6:30 PM, Andrei Alexandrescu wrote: On 8/25/11 6:10 PM, Walter Bright wrote: On 8/25/2011 6:04 PM, Nick Sabalausky wrote: Oh god no, don't ban that. I *like* to do that sort of thing: Unusual, but legitimate. I think I'll shelve the

Re: Optional braces

2011-08-26 Thread Steven Schveighoffer
On Fri, 26 Aug 2011 11:03:21 -0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: It's a legitimate concern, and there's no right response to it. My point is that the argument is weak and caving to it would be a mistake. In essence Nick claims he can't be bothered to change:

Re: Optional braces

2011-08-26 Thread Andrei Alexandrescu
On 8/26/11 8:48 AM, Steven Schveighoffer wrote: On Fri, 26 Aug 2011 11:03:21 -0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: It's a legitimate concern, and there's no right response to it. My point is that the argument is weak and caving to it would be a mistake. In essence

Re: Optional braces

2011-08-26 Thread Andrej Mitrovic
I've used this a few times: foreach (dir; dirs) foreach (string file; dirEntries(dir, SpanMode.shallow)) { if (file.isFile) // do something.. } And I only use this in short loops like this. It's more compact, I dislike having to create too much indentation. I don't see what banning

Re: Optional braces

2011-08-26 Thread bearophile
Andrej Mitrovic: I don't see what banning this buys us. That's not banned. Bye, bearophile

Re: Optional braces

2011-08-26 Thread bearophile
Marco Leise: Does your enhancement include other operators like '' or is it practically just for the 'check if flag is disabled' case? My enhancement request regards just a narrow case. (But the actual implementation of it may add some other related cases, I don't know). Bye, bearophile

Re: Optional braces

2011-08-26 Thread Adam Ruppe
we might as well get rid of the semicolon as well. You can have my semicolons when you pry them from my cold, dead hands.

Re: Optional braces

2011-08-26 Thread bearophile
Andrej Mitrovic: Ok, I thought this was included. It wasn't included in my original enhancement request. But now I don't exactly know what situations Andrei wants to disallow. Bye, bearophile

Re: Optional braces

2011-08-26 Thread Andrej Mitrovic
On 8/26/11, Adam Ruppe destructiona...@gmail.com wrote: we might as well get rid of the semicolon as well. You can have my semicolons when you pry them from my cold, dead hands. I'd kill them (the semicolons, not your hands :p) in places they're not needed anymore. And we already have that in

Re: Optional braces

2011-08-26 Thread Rainer Schuetze
On 26.08.2011 17:03, Andrei Alexandrescu wrote: On 8/25/11 9:13 PM, Walter Bright wrote: But I worry that we might wind up tarting up the language with too many a boatload of them, to the point where it becomes a confusing mass. At what point should Meg Ryan stop with the plastic surgery? :-)

Re: Optional braces

2011-08-26 Thread Jakob Ovrum
On 2011/08/27 1:52, Andrej Mitrovic wrote: Of course they're still needed in other places, but to be honest I'm tired of found foo, expected bla errors due to missing semicolons. You can have both semi-colons and nice error messages if you put some effort into the parser. Clang manages this

Re: Optional braces

2011-08-26 Thread Andrej Mitrovic
Cool stuff! DMD is almost there but it reports the line number of whatever comes next, even if there was only whitespace, e.g.: void main() { int foo = 2 } - error line here instead of above

Re: Optional braces

2011-08-26 Thread kennytm
Steven Schveighoffer schvei...@yahoo.com wrote: Hm... the only problem I see with simply disallowing if(a) if(b) is this: if(a) while(condition) if(b) statement; else // oops! this goes with if(b) statement; Or would this be disallowed as well? This could not be

Re: Optional braces

2011-08-26 Thread bearophile
kennytm: I've created a patch* for dangling else checking. I have not yet compiled and tried your code, but from what I see all the design decisions you have taken are good, including the error message (I think it doesn't need to contain dangling else because that's a different thing), the

Re: Optional braces

2011-08-25 Thread Nick Sabalausky
Walter Bright newshou...@digitalmars.com wrote in message news:j313kp$1fc1$1...@digitalmars.com... On 8/19/2011 8:12 AM, Andrei Alexandrescu wrote: One thing I'd subjectively like is to require braces on both branches of if/else if at least one has braces. It's rather simple to just

Re: Optional braces

2011-08-25 Thread Walter Bright
On 8/25/2011 6:04 PM, Nick Sabalausky wrote: Oh god no, don't ban that. I *like* to do that sort of thing: Unusual, but legitimate. I think I'll shelve the idea.

Re: Optional braces

2011-08-25 Thread bearophile
Walter: Nick Sabalausky wrote: Oh god no, don't ban that. I *like* to do that sort of thing: Unusual, but legitimate. I think I'll shelve the idea. This is the code by Nick Sabalausky: if(useThisFeature) foreach(x; 0..100) foreach(y; 0..100) if(blah blah long thing) if(simple

Re: Optional braces

2011-08-25 Thread Andrei Alexandrescu
On 8/25/11 6:10 PM, Walter Bright wrote: On 8/25/2011 6:04 PM, Nick Sabalausky wrote: Oh god no, don't ban that. I *like* to do that sort of thing: Unusual, but legitimate. I think I'll shelve the idea. It would be great to reconsider. The counter-argument is very weak. Andrei

Re: Optional braces

2011-08-25 Thread Walter Bright
On 8/25/2011 6:30 PM, Andrei Alexandrescu wrote: On 8/25/11 6:10 PM, Walter Bright wrote: On 8/25/2011 6:04 PM, Nick Sabalausky wrote: Oh god no, don't ban that. I *like* to do that sort of thing: Unusual, but legitimate. I think I'll shelve the idea. It would be great to reconsider. The

Re: Optional braces

2011-08-25 Thread kennytm
Walter Bright newshou...@digitalmars.com wrote: We've already put a number of special cases in the grammar to ward off bugs. But I worry that we might wind up tarting up the language with too many a boatload of them, to the point where it becomes a confusing mass. At what point should Meg

Re: Optional braces

2011-08-24 Thread kennytm
Walter Bright newshou...@digitalmars.com wrote: On 8/19/2011 8:12 AM, Andrei Alexandrescu wrote: One thing I'd subjectively like is to require braces on both branches of if/else if at least one has braces. It's rather simple to just disallow the form: if (a) if (b) statement

Re: Optional braces

2011-08-24 Thread Walter Bright
On 8/24/2011 1:09 AM, kennytm wrote: Not sure if it's a big enough problem, but what about dangling else of this form? if (a.length 0) foreach (i, ref e; a) if (i 0) e += a[i-1]; else // oops throw new Exception(empty array);

Re: Optional braces

2011-08-24 Thread Walter Bright
On 8/23/2011 3:32 PM, Andrei Alexandrescu wrote: Yah, disallowing complete and nested if/else pairs would be an annoyance (I'm not sure how big). Otherwise, Walter's idea sounds good to me. Walter, would you be okay with accepting if-if-else-else (at any depth) as a correct case and otherwise

Re: Optional braces

2011-08-24 Thread Timon Gehr
On 08/24/2011 06:22 PM, Walter Bright wrote: On 8/24/2011 1:09 AM, kennytm wrote: Not sure if it's a big enough problem, but what about dangling else of this form? if (a.length 0) foreach (i, ref e; a) if (i 0) e += a[i-1]; else // oops throw new Exception(empty array); That wouldn't be

Re: Optional braces

2011-08-23 Thread Walter Bright
On 8/19/2011 8:12 AM, Andrei Alexandrescu wrote: One thing I'd subjectively like is to require braces on both branches of if/else if at least one has braces. It's rather simple to just disallow the form: if (a) if (b) statement ^ error: use if(ab) or if(a){if(b)statement} and

Re: Optional braces

2011-08-23 Thread Timon Gehr
On 08/23/2011 10:46 PM, Walter Bright wrote: On 8/19/2011 8:12 AM, Andrei Alexandrescu wrote: One thing I'd subjectively like is to require braces on both branches of if/else if at least one has braces. It's rather simple to just disallow the form: if (a) if (b) statement ^ error: use if(ab)

Re: Optional braces

2011-08-23 Thread Andrei Alexandrescu
On 8/23/11 2:31 PM, Timon Gehr wrote: On 08/23/2011 10:46 PM, Walter Bright wrote: On 8/19/2011 8:12 AM, Andrei Alexandrescu wrote: One thing I'd subjectively like is to require braces on both branches of if/else if at least one has braces. It's rather simple to just disallow the form: if

Re: Optional braces

2011-08-22 Thread Ali Çehreli
On Sun, 21 Aug 2011 20:32:05 +0200, Jacob Carlborg wrote: Yes, the else is for the second if-statement, not the first one. That's why I always use braces when I have nested if-statements, at least for the outer if-statement. That rule is too complicated for me. :) My version is I always use

Re: Optional braces

2011-08-21 Thread Nick Sabalausky
Andrei Alexandrescu seewebsiteforem...@erdani.org wrote in message news:j2luh6$23bb$1...@digitalmars.com... One thing I'd subjectively like is to require braces on both branches of if/else if at least one has braces. Yuck! I'd really hate that.

Re: Optional braces

2011-08-21 Thread bearophile
Nick Sabalausky: Yuck! I'd really hate that. Recently I have converted 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

Re: Optional braces

2011-08-21 Thread Jacob Carlborg
On 2011-08-21 20:02, bearophile wrote: Nick Sabalausky: Yuck! I'd really hate that. Recently I have converted 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

Re: Optional braces

2011-08-21 Thread Jonathan M Davis
On Sunday, August 21, 2011 12:47:22 Nick Sabalausky wrote: Andrei Alexandrescu seewebsiteforem...@erdani.org wrote in message news:j2luh6$23bb$1...@digitalmars.com... One thing I'd subjectively like is to require braces on both branches of if/else if at least one has braces. Yuck! I'd

Re: Optional braces

2011-08-21 Thread Nick Sabalausky
bearophile bearophileh...@lycos.com wrote in message news:j2rh7g$2tfq$1...@digitalmars.com... To this innocent-looking D code, do you see the problem? void foo(Pair[] sol) { if (isSolution(sol[$-1])) if (!best.length || sol.length best.length) best = sol.dup; else

Re: Optional braces

2011-08-21 Thread Andrei Alexandrescu
On 8/21/11 4:02 PM, Nick Sabalausky wrote: bearophilebearophileh...@lycos.com wrote in message news:j2rh7g$2tfq$1...@digitalmars.com... To this innocent-looking D code, do you see the problem? void foo(Pair[] sol) { if (isSolution(sol[$-1])) if (!best.length || sol.length

Re: Optional braces

2011-08-21 Thread Timon Gehr
On 08/21/2011 11:02 PM, Nick Sabalausky wrote: bearophilebearophileh...@lycos.com wrote in message news:j2rh7g$2tfq$1...@digitalmars.com... To this innocent-looking D code, do you see the problem? void foo(Pair[] sol) { if (isSolution(sol[$-1])) if (!best.length || sol.length

Re: Optional braces

2011-08-21 Thread bearophile
Andrei Alexandrescu: Yah, it's pretty neat, and very much in the spirit of D. I'd missed it. Thank you Andrei. This problem is know as Dangling else problem. When a bug receives a name, you know it's common enough. This is one of the about one dozen of tiny/small breaking changes I'd like for

Re: Optional braces

2011-08-21 Thread Jonathan M Davis
On Sunday, August 21, 2011 20:36:55 bearophile wrote: Andrei Alexandrescu: Yah, it's pretty neat, and very much in the spirit of D. I'd missed it. Thank you Andrei. This problem is know as Dangling else problem. When a bug receives a name, you know it's common enough. This is one of the

Re: Optional braces

2011-08-21 Thread bearophile
Jonathan M Davis: Except that it's not a bug. It's an issue that crops up in grammars for programming languages. Right, I have just seen I was wrong :-) There is classic solution to the problem which D follows. So, there is no ambiguity, and there is no bug. It's very much by design.

Optional braces

2011-08-19 Thread Jacob Carlborg
, but compared with Java, D also allow try, catch and finally statements to have optional braces. What about extending this to allow optional braces everywhere, where the braces contain a single expression? I'm thinking this will be most useful for functions/methods, templates and delegates. Specially

Re: Optional braces

2011-08-19 Thread Timon Gehr
expression. In D this is true as well, but compared with Java, D also allow try, catch and finally statements to have optional braces. What about extending this to allow optional braces everywhere, where the braces contain a single expression? I'm thinking this will be most useful for functions

Re: Optional braces

2011-08-19 Thread Trass3r
Am 19.08.2011, 14:16 Uhr, schrieb Timon Gehr timon.g...@gmx.ch: I think this makes code harder to read for no obvious benefit. I don't think this is any better than class Foo{ private int a_; int a(){return a_;} int a(int a){return a_ = a;} } +1 Optional braces should

Re: Optional braces

2011-08-19 Thread Ulrik Mikaelsson
don't think this is any better than class Foo{     private int a_;     int a(){return a_;}     int a(int a){return a_ = a;} } +1 Optional braces should be limited to statements.

Re: Optional braces

2011-08-19 Thread kennytm
= a;} } +1 Optional braces should be limited to statements. I agree. Besides, a minor problem is that 'if' statements may be mistaken as template conditions: void f1(T)(T x) if (isFoo!T) { x ++; } void f2(T)(T x) { if (isFoo!T) { x ++; } }

Re: Optional braces

2011-08-19 Thread Andrei Alexandrescu
expression. In D this is true as well, but compared with Java, D also allow try, catch and finally statements to have optional braces. What about extending this to allow optional braces everywhere, where the braces contain a single expression? I'm thinking this will be most useful for functions/methods

Re: Optional braces

2011-08-19 Thread Timon Gehr
like if, while, for and so on, containing only one expression. In D this is true as well, but compared with Java, D also allow try, catch and finally statements to have optional braces. What about extending this to allow optional braces everywhere, where the braces contain a single expression? I'm

Re: Optional braces

2011-08-19 Thread Jacob Carlborg
if, while, for and so on, containing only one expression. In D this is true as well, but compared with Java, D also allow try, catch and finally statements to have optional braces. What about extending this to allow optional braces everywhere, where the braces contain a single expression? I'm

Re: Optional braces

2011-08-19 Thread Jacob Carlborg
;} int a(int a){return a_ = a;} } +1 Optional braces should be limited to statements. I agree. Besides, a minor problem is that 'if' statements may be mistaken as template conditions: void f1(T)(T x) if (isFoo!T) { x ++; } void f2(T)(T x) { if (isFoo!T) { x ++; } } Oh, never