From: "Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org>
Subject: Re: Tables vs functions (was Re: Anonymous array clarification.)
Date: Mon, 20 Aug 2001 13:28:52 -0400
Date: 2001-08-20T17:28:55+00:00 [thread overview]
Message-ID: <9lrhcn$9lc$1@nh.pace.co.uk> (raw)
In-Reply-To: un14uy8v0.fsf_-_@infomatch.com
Or as an alternative:
> function Tomorrow(A_Day : in Day) return Day is
> begin
> return Day'Succ(A_Day);
exception
when Constraint_Error =>
return Day'First ;
> end Tomorrow;
There is, of course, going to be some debate about using exceptions for
conditions you expect to happen. However, I'd point out that the code is a
bit more brief and that in some implementations it might be (on the average)
faster - for whatever that's worth. Its just an alternate implementation
style. :-)
Which would I personally use? I'd usually go with what you described. There
may be occasional uses of the Constraint_Error trap in things I write of
this nature - I'm partial to that technique when implementing saturated
arithmetic. Dunno if there is any consensus that it should be one way or
another in this case - but its a good one to put in a programming style
guideline. Like formatting rules, I'd go with whatever the style guide
recommends for a given project.
MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas www.pacemicro.com
Enabling the digital revolution
e-Mail: marin.condic@pacemicro.com
Web: http://www.mcondic.com/
"Ray Blaak" <blaak@infomatch.com> wrote in message
news:un14uy8v0.fsf_-_@infomatch.com...
>
> Hmm.
>
> function Tomorrow(A_Day : in Day) return Day is
> Result : Day;
> begin
> if A_Day < A_Day'Last then
> Result := Day'Succ(A_Day);
> else
> Result := Day'First;
> end if;
> return Result;
> end Tomorrow;
>
> Doesn't seem too complicated, looks the same to the user, is just as time
> efficient, is more space efficient, and works for any size of
> array/enumeration type.
>
> It also is more robust, since one does not have to tediously type out the
> items in a possibly erroneous way.
>
> On the other hand, tables are useful when the calculations are expensive,
> difficult or tedious to describe algorithmically, or the values change
> according to subsequent data inputs.
>
> --
> Cheers, The Rhythm is around me,
> The Rhythm has control.
> Ray Blaak The Rhythm is inside me,
> blaak@infomatch.com The Rhythm has my soul.
next prev parent reply other threads:[~2001-08-20 17:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-20 6:18 Anonymous array clarification McDoobie
2001-08-20 8:03 ` Phil Thornley
2001-08-20 16:49 ` Tables vs functions (was Re: Anonymous array clarification.) Ray Blaak
2001-08-20 17:28 ` Marin David Condic [this message]
2001-08-20 21:02 ` Samuel T. Harris
2001-08-21 14:13 ` Marin David Condic
2001-08-20 8:29 ` Anonymous array clarification David C. Hoos, Sr.
2001-08-20 10:26 ` Larry Hazel
2001-08-20 13:37 ` Samuel T. Harris
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox