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,XPRIO autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,552027c53f35ddb8,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-30 03:32:46 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news1.optus.net.au!optus!news.mel.connect.com.au!news.syd.connect.com.au!iridium.webone.com.au From: "Alan and Carmel Brain" Newsgroups: comp.lang.ada Subject: Avoiding Kludges Date: Wed, 30 Oct 2002 22:45:28 +1100 Organization: Web One Internet http://webone.com.au Message-ID: <3dbfc357$2@iridium.webone.com.au> NNTP-Posting-Host: iridium.webone.com.au X-Trace: merki.connect.com.au 1035977564 4531 210.8.44.3 (30 Oct 2002 11:32:44 GMT) X-Complaints-To: abuse@connect.com.au NNTP-Posting-Date: 30 Oct 2002 11:32:44 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Original-NNTP-Posting-Host: dial-ctb03251.webone.com.au X-Original-Trace: 30 Oct 2002 22:32:39 +1000, dial-ctb03251.webone.com.au Xref: archiver1.google.com comp.lang.ada:30222 Date: 2002-10-30T11:32:44+00:00 List-Id: "Dr Nancy's Sweetie" wrote > At this point, several alternative approaches occurred to me. The first is > to have the function return an illegal logical location -- made difficult > because the "Location_Type" is range limited to only legal possibilities. > It could be kludged to have a "Any_Location_Type", which would include some > impossible spots, and "Real_Location_Type", which would be only legal > spots, and then cast things around, and then . . . Well, it's starting to > sound pretty kludgy Indeed it is. > Then I realised that this could also be done with an exception: But it's not an unusual or erroneous situation. Bad Form. > But of these last two approaches, I don't have a feeling for which one is > Good Ada Style(tm). Neither: Good Ada Style , valid for -83 and -95 is to return something of this type type Mouse_Location_Type( InWindow : boolean := false) is record case InWindow is when true => CoOrdinate : Location_Type; when false => null; end case; end record; When referencing something of this type, you'll have to do an explicit test to see if CoOrdinate exists. If doing a test on the co-ordinates, the "and then" clause is useful. Example: -- Get the mouse location and see if it's within normal bounds. begin MouseLocation := GetLocation; if MouseLocation.InWindow and then InBounds(MouseLocation.CoOrdinate) then -- do stuff else -- do other stuff. end if; exception when others => raise; -- No expected exceptions, -- and we wouldn't know what to do with one -- if we get one. So kick it upstairs to -- a higher authority. end; > My own inclination is to write two functions and use an if, but I thought > it might be worthwhile to ask people with a better sense of the style. My qualifications as a Style Guru: I've got a dozen successful Ada-83 projects under my belt over nearly 20 years, and was in charge of the Ada-95 spaceflight avionics for FedSat, due for launch in December. The style above is what I'd recommend for practical use in large projects. Note that I make no claim to infallibility. Regards, AEB -- Alan & Carmel Brain mailto:aebrain@webone.com.au