February 27, 2005
"Matthew" <admin@stlsoft.dot.dot.dot.dot.org> wrote in message news:cvrknn$250a$1@digitaldaemon.com...
> 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
On Sun, 27 Feb 2005 08:43:41 +0000 (UTC), Manfred Nowak <svv1999@hotmail.com> wrote:
> "Matthew" <admin@stlsoft.dot.dot.dot.dot.org> 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.

True.

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

switch() {
case x:
if (a);    <-accidental semi-colon
  break;
..unreachable..
..etc..

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 reachable."

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.

Regan
February 28, 2005
"Walter" <newshound@digitalmars.com> wrote in message news:cvrhvs$2222$1@digitaldaemon.com...
>
> "Matthew" <admin.hat@stlsoft.dot.org> wrote in message news:cvr6lh$1ndv$1@digitaldaemon.com...
>> Exactly. But did the compiler balk on it, with a helpful message? No, and
> no!
>>
>> "John C" <johnch_atms@hotmail.com> wrote in message
> news:cvq1q3$h6o$1@digitaldaemon.com...
>> >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
"Manfred Nowak" <svv1999@hotmail.com> wrote in message news:cvs17s$2hoh$1@digitaldaemon.com...
> "Matthew" <admin@stlsoft.dot.dot.dot.dot.org> 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