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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.20.87 with SMTP id 84mr2690721iou.31.1511984632828; Wed, 29 Nov 2017 11:43:52 -0800 (PST) X-Received: by 10.157.11.207 with SMTP id 73mr88528oth.2.1511984632751; Wed, 29 Nov 2017 11:43:52 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.kjsl.com!usenet.stanford.edu!i6no936745itb.0!news-out.google.com!193ni1346iti.0!nntp.google.com!i6no936741itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 29 Nov 2017 11:43:52 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=155.148.6.150; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 155.148.6.150 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <7e91dadf-baa7-4742-b0b9-44ab7e5731b8@googlegroups.com> Subject: Re: When to use formal discrete type? From: Shark8 Injection-Date: Wed, 29 Nov 2017 19:43:52 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:49257 Date: 2017-11-29T11:43:52-08:00 List-Id: On Wednesday, November 29, 2017 at 12:04:35 PM UTC-7, Victor Porton wrote: >=20 > Because it easily generalizes from discrete types to arbitrary private=20 > types, should I do generalization? >=20 > What of (generalizing for all private types or not) the two is better: >=20 > a. for clarity of code; >=20 > b. for performance? >=20 > It there a noticeable difference in performance if I generalize? My rule of thumb is use the most general type as reasonably possible -- so,= if you aren't using things like X'First and X'Succ(Value) go ahead and mak= e the parameter private. (On the other hand, if you do find yourself using = a value for first/last and/or functions for previous/next consider using mo= re restrictive generic formal parameter; of course, your design might make = it impossible to use a discrete-formal [like, say, modeling integrals (for = certain models)].) As for performance, I would recommend that you first benchmark and hotspot-= analyze your code: it's typically dumb to spend hours and hours super-optim= izing something from O(n**4) to O(n) if n always <=3D 3. -- Chances are tha= t your intuition as to what's a /real/ performance hit is going to be wrong= .