Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: using type? with switch

From: joel:neely:fedex at: 1-Oct-2001 16:06

Hi, Cal, Cal Dixon wrote:
> ... I've got one tiny addition below ;-] ... > > 3) use reduce to solve the WORD! / DATATYPE! problem and always > have BLOCK! as the first option in the switch to avoid the > "feature" of matching the first action block. >
Thanks for the additional option! Permit me to add one tiny additional addition ;-} This is the kind of thing that can drive a maintenance programmer (anybody but the original author, or the original author after only one significant distraction) completely around the bend. Suppose that a subsequent edit involves adding an option to the list of case/action pairs. The person performing that edit might look at code like the following: ;; ... cases: reduce [ block! [ ... block action ... ] integer! [ ... integer action ... ] string! [ ... string action ... ] email! [ ... email action ... ] ] ;; ... switch/default type? somevar cases [ ... default action ... ] ;; ... and observe (correctly!) that all of the case selectors are distinct and therefore conclude (incorrectly!) that the order doesn't matter. Needing to add an additional case, (s)he might then decide to stick the new case at the beginning of the case/action pairs... cases: reduce [ url! [ ... url action ... ] block! [ ... block action ... ] integer! [ ... integer action ... ] string! [ ... string action ... ] email! [ ... email action ... ] ] and then be terribly confused when the code goes horribly awry! My suggestion would be either to avoid such subtly fragile constructions or to insert comments warning subsequent readers and maintainers that the BLOCK!/action pair *must* remain as the first choice. Having seen an entire weekend lost in the search for a missing comma... -jn- -- Of course, implementing a compiler for modern C++ must be the second worst C++ programmer's nightmare ;-) [the first is having to work in OO Cobol]. -- Graziano Lo Russo joel[dot[FIX[PUNCTUATION[neely[at[fedex[dot[com