Re: no case for CASE

new topic     » goto parent     » topic index » view thread      » older message » newer message

BABOR, JIRI wrote:
>
> Irv Mullins wrote:
>
> >Here's an example clipped from a progam I wrote some time ago:
> >Purpose: to handle user input to a menu:
> >
> >--Pascal version:
> >   case key of esc    : fini := true;
> >               'P'    : dec(indx);
> >               'N',^M : inc(indx);
> >               'F'    : indx := 0;
> >               'E'    : if editmode then SO_DATA.MENU;
> >   end; {case key}
> >
> >--Euphoria version (translated)
> >  if compare(key,esc) = 0 then fini = TRUE
> >  elsif compare(key,'P') = 0 then indx = indx - 1
> >  elsif compare(key,'N') = 0 then indx = indx + 1
> >  elsif compare(key,ctlM ) = 0 then indx = indx + 1
> >  elsif compare(key,'F') = 0 then indx = 0
> >  elsif compare(key,'E') = 0 then
> >       if editmode then SO_DATA_MENU end if
> >  end if
> >--
> >
> >Anyone want to guess which is
> >(1) easier to understand
> >(2) less typing
> >(3) less likely to have "unexpected consequences" (bugs)?
>
> Irv, are you prepared to be a bit fairer, and leave out the
> unnecessary, counter-intuitive compare tests:
>
>     if key = esc then fini = TRUE
>     elsif key = 'P'  then indx = indx - 1
>     elsif key = 'N' or key = ctlM then indx = indx + 1
>     elsif key = 'F' then indx = 0
>     elsif key = 'E' then
>          if editmode then SO_DATA_MENU end if
>     end if
>
> Slightly more typing, yes, but you may even change your mind about
> the rest. Jiri



        Maybe it's just me but an if-then structure feels
more natural and intuitive, case has always seemed akward and
to rigid/terse to me (at least in c, haven't used it anywhere
else).
        Of course this probably stems from programing almost
exclusively on the comodore 64 from '84 till about mid 1990.
(it's built in basic had NO case statement, and of course there
isn'ta case in assembler).

        It seems to me most of what people are asking for in
Euphoria could be done by just adding some macro like facilities
to the Editor/proprocessor, leaving the language itself simple
and effecient/fast. This would let RDS put more effort to core
issues like 2.0 final, as others could do work on the editor to
put the features THEY want ( then everyone who REALLY wants a
custom version of euphoria bad enough could have one!!)

                Kasey

                Kasey.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu