there still is a case for CASE
- Posted by Mike <mdeland at NWINFO.NET> Mar 08, 1998
- 760 views
Irv wrote: ------------------------------------------- The real reason for wanting a 'case' statement was to simplify long if .. then .. elsif .. then .. else .. end if statements. >>I'd like to clarify that a bit...simplify, in this case, >>to me, is to simplify _understanding_ or >>_readability_....not typing necessarily. >>when I read a case statement like the one >>below, I can figure out what it's doing much >>faster and easier...they are far more instantly >>intuitive than their counterpart if.then.elsif >>(to me that is) (Not that they're all that bad, compared with other languages, thanks to the elsif!) >>no. they are not bad at all. I keep wondering, >>as Jiri intuned below, if we should 'bother' >>trying to make this case statement... >>{continued below} --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} Anyone want to guess which is (1) easier to understand >>the real goal IMHO (2) less typing >>I could care less, frankly, about typing. I took a typing >>class and saving typing is not my primary concern. (3) less likely to have "unexpected consequences" (bugs)? >>the other half of the real goal. if coding is intuitive, >>and reading that subsequent code is intuitive, >>bughunting becomes almost trivial >>{continued} >>however, when I see the above as compared to the >>if.then.elsif that Jiri proposed, I realize that it >>is indeed worth it to attempt to develop a coding >>structure that mimics case. Whatever procedure we come up with would have to be clearer and shorter than the Euphoria if.. elsif.. code, or it wouldn't be worth doing. >>agreed. Pete's code is really good code IMHO. >>it's fast at runtime, neat and clean.... >>alas, it's also a bit cumbersome... >>gotta keep looking -------------------------------------------------- Jiri wrote: -------------------------------------------------- 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. >>not worried 'bout the typing personally.... >>yes, that is clean and neat code, but it >>still takes me longer to decipher... >>it's just not quite "instantly intuitive" ----------------------------------------------------- >>another way to potentially implement the case >>may be with a preprocessor. I don't know >>much about preprocessors (PP) as they relate >>to Euph, but it's my understanding that >>david cuny (i believe) has written one that >>is quite good. haven't had time to tinker >>with it. >>the PP could (i'm guessing) translate the >>case code to if.then.elsif to a temp file >>that euph runs instead of the main .ex file >>this way, we don't have to over complicate >>euph with features that aren't wanted by >>the masses or with features that may >>slow down run time....best of both worlds >>perhaps? >>Mike (sorry for the reverse >> quoting, only way I could include both irv and jiri's messages) -------------------------------------- If it wasn't for typos, I'd never get any coding done at all. ;)