comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: When to use formal discrete type?
Date: Wed, 29 Nov 2017 11:43:52 -0800 (PST)
Date: 2017-11-29T11:43:52-08:00	[thread overview]
Message-ID: <7e91dadf-baa7-4742-b0b9-44ab7e5731b8@googlegroups.com> (raw)
In-Reply-To: <ovn0bv$1rto$1@gioia.aioe.org>

On Wednesday, November 29, 2017 at 12:04:35 PM UTC-7, Victor Porton wrote:
> 
> Because it easily generalizes from discrete types to arbitrary private 
> types, should I do generalization?
> 
> What of (generalizing for all private types or not) the two is better:
> 
> a. for clarity of code;
> 
> b. for performance?
> 
> 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 make 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 more 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-optimizing something from O(n**4) to O(n) if n always <= 3. -- Chances are that your intuition as to what's a /real/ performance hit is going to be wrong.


  reply	other threads:[~2017-11-29 19:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-29 19:04 When to use formal discrete type? Victor Porton
2017-11-29 19:43 ` Shark8 [this message]
2017-11-29 21:07   ` Dmitry A. Kazakov
2017-11-29 21:05 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox