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=0.6 required=5.0 tests=BAYES_00,TO_NO_BRKTS_FROM_MSSP autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1ce805592e46d231 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-05 07:20:03 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!feed.textport.net!newsranger.com!www.newsranger.com!not-for-mail Newsgroups: comp.lang.ada From: Ted Dennison References: <9n24g4$17q$1@snipp.uninett.no> <9n279a$1ua$1@snipp.uninett.no> <3B94B4B4.CE1955D6@nbi.dk> <9n2ctk$36v$1@snipp.uninett.no> <3b95eca7.5408987@news.demon.co.uk> Subject: Re: (elementary question) Test on type ? Message-ID: X-Abuse-Info: When contacting newsranger.com regarding abuse please X-Abuse-Info: forward the entire news article including headers or X-Abuse-Info: else we will not be able to process your request X-Complaints-To: abuse@newsranger.com NNTP-Posting-Date: Wed, 05 Sep 2001 10:19:55 EDT Organization: http://www.newsranger.com Date: Wed, 05 Sep 2001 14:19:55 GMT Xref: archiver1.google.com comp.lang.ada:12751 Date: 2001-09-05T14:19:55+00:00 List-Id: In article <3b95eca7.5408987@news.demon.co.uk>, John McCabe says... > >I don't know whether you missed the original message, but it >contained: > >> Assume: >> >> >> -- specification : >> generic >> type T is (<>); >> function F(X : T) return Float; Ahh, you're right; I did miss that. This issue does actually come once in a while too, when you've got code that needs to be mostly the same, except for one little bit. I think you pretty much have to hack it. Approaches I have seen: Make one generic for each type. Variant 1: Copy and pase the code (maintainence problems). Variant 2: Use a common subprogram for the common code (cool, but only works if you don't need to use the generic part in the common code). Make one generic, hack the difference. Hack 1: Make the user supply a boolean designating which code path to take. (flag coupling - fairly bad) Hack 2: Make the user supply the non-common code themselves as a procedure parameter. (works well if the non-common stuff can be put together, and it doesn't rely on package-internal stuff, and you can trust the clients to get this code right. Not so good if its stuff the clients shouldn't have to worry about doing themselves. Hack 1 is really just a special case of Hack 2, where the routine being supplied is an "Is_Integer" routine, simplified to a boolean. Somewhere in between these two extremes you may find a good spot. --- T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html home email - mailto:dennison@telepath.com