View mode: basic / threaded / horizontal-split · Log in · Help
February 27, 2005
Re: More "switch/default" woes
"Matthew" <> wrote in message
> Yet again, my friend, you're prescribing behaviour with enormous
> ramifications on the entire (current and potential) D community as a
> result of your own personal experience and development style. I have to
> say, as I've said many times before, that I think this is a bad general
> strategy, and this is a specific acute example of it.

D can't help but be a reflection of my personal experience and development
style, just as C, C++, Ruby, Python, Perl, etc., are each a reflection of
their principal designers.

> I had actually forgotten the 'deliberate' nature of this, and was
> feeling a little Kris-guilt at having made too much of a big deal about
> what was obviously a (temporary) compiler error.

You argue for the compiler to complain about dead code in some
circumstances, but require the programmer to insert dead code in other
circumstances (the switch default, and the fallthrough return). Trying to
simultaneously codify both into the language rules would be tricky.

> Now I realise the full
> horror of it, I realise I was far too easy on it. This is bad stuff. :-(

The following code is perfectly legal C++, too:

   int foo()
       return 1;
       return 2;

There are many horrors in C++, but that one isn't. While it's "obviously"
wrong, there are many more subtle cases where things aren't so clear (many
popular compilers generate spurious and erroneous warnings about supposedly
dead code), and as I posted before, sometimes it is convenient to allow such
when trying to rapidly develop/test/debug code.
February 27, 2005
Re: More "switch/default" woes
On Sun, 27 Feb 2005 08:43:41 +0000 (UTC), Manfred Nowak  
<> wrote:
> "Matthew" <> wrote:
> [...]
>> This is bad stuff. :-(
> No. I assist Walter with another argument: You wrote `break'---so
> you meant `break'.
> It is not the job of the compiler to declare some code as erroneous
> when you expressively wanted it.


IMO Matthews point was that the compiler should detect 'accidental'  
unreachable code. i.e.

switch() {
case x:
if (a);    <-accidental semi-colon

Note: The above is actually illegal D, as ; is not a valid empty statement  
{} must be used instead, so, the good news is that D does detect the  
accidental break, in this case.

Are there other examples of accidental unreachable code where the root  
cause is actually something else, like the ; {} thing above?

> Otherwise what would D end in?
> Adding the `default' case to a `switch' statement is an error
> because the other cases cover all possible values and therefore the
> code of the `default' case is unreachable?
> `if(e())return; <code>' is an error because the function `e' can be
> proved to compute `true' and therefore <code> is unreachable?
> `version(null)' without an `else' is an error because this version
> may not be set at the command line and therefore the code may be
> unreachable?
> Unused variable? Unused member of a class? Unused class when
> importing a module? Linking to a library only possible if you use
> all and every construct in the library?

I agree with you "In the general case it is undecidable, whether code is  

However, it's possible (as in my example above) to detect the error that  
causes the unreachable code, meaning the programmer can still  
intentionally do it, but is less likely to accidentally do it.

February 28, 2005
Re: More "switch/default" woes
"Walter" <> wrote in message news:cvrhvs$2222$
> "Matthew" <> wrote in message
> news:cvr6lh$1ndv$
>> Exactly. But did the compiler balk on it, with a helpful message? No, and
> no!
>> "John C" <> wrote in message
> news:cvq1q3$h6o$
>> >I don't think the code is reachable. There's a break after the first
> combo box is created.
> I tend to generate lots of unreachable code when trying to isolate a
> problem. It's a nuisance having the compiler complain about it.

Why so? Isn't it actually a good thing for the compiler to nag you to fix up something which you admit is temporary?
February 28, 2005
Re: More "switch/default" woes
"Manfred Nowak" <> wrote in message news:cvs17s$2hoh$
> "Matthew" <> wrote:
> [...]
>> This is bad stuff. :-(
> No. I assist Walter with another argument: You wrote `break'---so
> you meant `break'.

Yeah, but there was no case!

> It is not the job of the compiler to declare some code as erroneous
> when you expressively wanted it.

No-one's saying it is.
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home