Switch and break

2012-01-19 Thread RenatoL
Just curious: why in D we are not obligated to use break in every branch of a swicth structure? That is: switch (i) { case 1: writeln(You wrote 1); case 2: writeln(You wrote 2); case 3:

Re: Switch and break

2012-01-19 Thread Timon Gehr
On 01/19/2012 10:55 PM, RenatoL wrote: Just curious: why in D we are not obligated to use break in every branch of a swicth structure? That is: switch (i) { case 1: writeln(You wrote 1); case 2: writeln(You wrote 2);

Re: Switch and break

2012-01-19 Thread RenatoL
Compile with -w enabled and the compiler will complain about implicit fall-through. You can use goto case/goto default for explicit fall- through. This gives a little relief

Re: Switch and break

2012-01-19 Thread Derek
On Fri, 20 Jan 2012 08:55:06 +1100, RenatoL rex...@gmail.com wrote: Just curious: why in D we are not obligated to use break in every branch of a swicth structure? a) C/C++ compatibility b) Walter likes this construct and uses it in his code. I use a language that enables the coder to choose

Re: Switch and break

2012-01-19 Thread bearophile
Timon Gehr: Compile with -w enabled and the compiler will complain about implicit fall-through. And eventually this specific -w behavior will be enforced even without -w, becoming part of D2, just like the use of override. Bye, bearophile

Re: Switch and break

2012-01-19 Thread Manfred Nowak
RenatoL wrote: why in D we are not obligated This depends on how the designer wants the coders to think about the semantics of a label. If a label _always_ is an _additional_ entry into an otherwise linear sequence of commands, then fall-through as standard is the consequence. If a label

Re: Switch and break

2012-01-19 Thread Jonathan M Davis
On Thursday, January 19, 2012 22:10:19 Peter Alexander wrote: Consistency with C and C++ mainly. Some people find it convenient, but it is unarguably a frequent source of bugs that we could do without. I'd be _very_ annoying if you couldn't do fall-through with switch-statements. That's a

Re: Switch and break

2012-01-19 Thread Matej Nanut
On 20 January 2012 00:46, Jonathan M Davis jmdavisp...@gmx.com wrote: On Thursday, January 19, 2012 22:10:19 Peter Alexander wrote: Consistency with C and C++ mainly. Some people find it convenient, but it is unarguably a frequent source of bugs that we could do without. I'd be _very_

Re: Switch and break

2012-01-19 Thread Jonathan M Davis
On Friday, January 20, 2012 01:03:21 Matej Nanut wrote: I like the error DMD (-w) gives in this situation a lot. It has saved me precious minutes of debugging on more than one occasion. :) And I never liked ‘warning:’s anyway. If something is dangerous enough to warrant a warning, the

Re: Switch and break

2012-01-19 Thread Era Scarecrow
== Quote from Derek (ddparn...@bigpond.com)'s article I use a language that enables the coder to choose to use fall through or not. By default, falling through is disabled, so to produce the D effect one can code ... switch i do case 1 then writeln(You wrote

Re: Switch and break

2012-01-19 Thread H. S. Teoh
On Thu, Jan 19, 2012 at 07:19:07PM -0500, Jonathan M Davis wrote: [...] Personally, I always compile with -w and have increasingly come to agree with Walter's thinking on this. I've long believed that responsible programmers don't commit code with warnings in it. And if warnings are never

Re: Switch and break

2012-01-19 Thread Jonathan M Davis
On Friday, January 20, 2012 00:38:49 Era Scarecrow wrote: Personal experience in a program (not a language) is that having certain options on automatically usually is more of an annoyance, than manually turning them on. With that said, having explicit fall through sounds more useful than