From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e429176c9adb07b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-20 10:47:45 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc53.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: [OT] Best way to isolate a GUI? References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 12.234.13.56 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc53 1045766864 12.234.13.56 (Thu, 20 Feb 2003 18:47:44 GMT) NNTP-Posting-Date: Thu, 20 Feb 2003 18:47:44 GMT Organization: AT&T Broadband Date: Thu, 20 Feb 2003 18:47:44 GMT Xref: archiver1.google.com comp.lang.ada:34290 Date: 2003-02-20T18:47:44+00:00 List-Id: >Oh, there may be cases here and there. And its always easy to construct an >artificial scenario where variant records look better. Just that in >practice, the places where I've used variant records have usually turned out >to be more elegantly and less painfully dealt with by tagged records. Not two weeks ago I had to write code to watch data going by and catch certain patterns, essentially a simple kind of parser. Each pattern required somewhat different information to be accumulated, so type pattern_kinds is (none, a,b,c); type states(kind : pattern_kinds := none) is record case kind is when none => null; when a => -- data accumulators for pattern type a when b => -- data accumulators for pattern type b etc current_state : states(kind=>none); did the job nicely. To change state takes a simple assignment, not any freeing or allocating of classwide pointers. The assignment has to be a whole record assignment, so there's no chance of forgetting to initialize some part of the data for pattern x. If a new pattern is added it needs no modifications to the code for existing patterns. If new data fields are added for pattern x, the compiler will flag any assignment that fails to include the new field in the aggregate. An attempt to use a field of pattern "a" while "kind = b", will be caught. How would you do this with tagged records?