October 29, 2001
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3BD8AEA0.318DCD6E@deming-os.org...

> IMHO, C's switch is very "un-C-like."  It's the only language construct that has conceptual "blocks of code" but ditches the {}.  I would opine that this new syntax is MORE C-like than C.    :)

Totally agreed. I always hated that switch syntax in C.

Just one thing. If we are concerned about compatibility (with C),
then maybe an alternative syntax - on(...) instead of case(...)
and "else" instead of "default":

    switch (list->data)
    {
        on (BIG)
        {
            list->bigflag = true;
            continue case(SMALL);
               // continues into whichever case handles SMALL...
               // even though it turns out
               // that that case also handles MEDIUM
        }

        on (SMALL, MEDIUM)
        {
            init();
        }

        else
        {
            throw exception;
        }
    }

This way, on() block should be equal to usual C case block enclosed in brackets and with break; at the end. Not only this allows to port existing code easily, but also to mix both versions:

    switch (list->data)
    {
        case BIG:
            list->bigflag = true;
            // no break so go further

        on (SMALL, MEDIUM)
        {
            init();
            // now break
        }

        else    // could be default: as well
        {
            throw exception;
        }
    }


October 29, 2001
EvilOne wrote:

> Just one thing. If we are concerned about compatibility (with C),
> then maybe an alternative syntax - on(...) instead of case(...)
> and "else" instead of "default":

That might make sense.  I'm not 100% sold on it, but it's not bad...

> This way, on() block should be equal to usual C case block enclosed in brackets and with break; at the end. Not only this allows to port existing code easily, but also to mix both versions:

In theory, I agree.  However, it is laden with problems.  For example, in the example code you give, why does the BIG case fall through?  It doesn't seem evident from the structure.  If we are going to allow both types, then I think that we should either disallow mixing in a given switch() block, or create a new keyword that indicates that we are using the new syntax.

>     switch (list->data)
>     {
>         case BIG:
>             list->bigflag = true;
>             // no break so go further
>
>         on (SMALL, MEDIUM)
>         {
>             init();
>             // now break
>         }
>
>         else    // could be default: as well
>         {
>             throw exception;
>         }
>     }

--
The Villagers are Online! villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]


October 29, 2001
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3BDD698E.EDA2E4F@deming-os.org...

> > This way, on() block should be equal to usual C case block enclosed in brackets and with break; at the end. Not only this allows to port existing code easily, but also to mix both versions:
>
> In theory, I agree.  However, it is laden with problems.  For example, in the example code you give, why does the BIG case fall through?  It doesn't seem evident from the structure.  If we are going to allow both types, then I think that we should either disallow mixing in a given switch() block, or create a new keyword that indicates that we are using the new syntax.

I wouldn't say that C switch makes it evident that cases fall through as well. =)
In fact, I believe that "case" should be left mostly for compatibility reasons, especially since most people here agreed that it's
actually rather "anti-C'ish" syntactically. If you want strict, ensured behaviour, you can always use whatever new form will be
there, no?


1 2 3
Next ›   Last »