From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Q: Trouble creating array and discriminated type
Date: Sat, 21 Jan 2017 10:41:00 +0100
Date: 2017-01-21T10:41:00+01:00 [thread overview]
Message-ID: <o5va89$ta3$1@dont-email.me> (raw)
In-Reply-To: <83409c51-59d3-4205-9eeb-5467de09f069@googlegroups.com>
On 01/20/2017 11:55 PM, b.mcguinness747@gmail.com wrote:
>
> I would appreciate help in solving these problems. One of the main purposes
> for creating this code is for me to become more familiar with the Ada
> language. I am much more familiar with Java, so I may not be looking at this
> with an Ada mindset.
It's very rare in Ada to have arrays with lower bounds of zero; code with lots
of that usually reflects thinking warped by a poorly designed language in which
all arrays have a lower bound of zero. Except when an array is serving as a map,
it is usually more intuitive to use a lower bound of 1: we talk of being "1st in
line" when at the head of a queue, or the 1st letter of a word.
Another way to put this is that having a fixed lower bound forces a translation
from the problem concept to the language index concept, introducing an
opportunity for error. Ada allows the problem concept to be used as the index,
eliminating that opportunity.
My 1st (not 0th) programming job involved a language in which all arrays had
lower bounds of 1, and we had data for the years 1600-1960. Translating from
years to indices was a source of errors, so this is not just an academic problem.
It's also useful sometimes to have non-numeric indices, so Ada allows
enumeration types as indices, too.
In addition to using index ranges that reflect your problem rather than the
constraints of some language (I suspect your problem domain has identifying
values other than 0 .. 677 for those indices), I'd also recommend eliminating
all anonymous types; having to explicitly define and name all types often has a
clarifying effect on one's thinking. This is especially true for anonymous
access types, which have complicated rules no one completely understands.
Gautier has explained a likely reason for your constant-array declaration
errors, and Wright has shown the typical way such things are declared in Ada.
It's probably a good idea to defer the discussion of discriminated records,
constrained and unconstrained variables, and function results as objects until
after you've digested what you've had so far.
--
Jeff Carter
"Mr. President, we must not allow a mine-shaft gap!"
Dr. Strangelove
33
next prev parent reply other threads:[~2017-01-21 9:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-20 22:55 Q: Trouble creating array and discriminated type b.mcguinness747
2017-01-20 23:48 ` gautier_niouzes
2017-01-21 7:23 ` Simon Wright
2017-01-21 9:41 ` Jeffrey R. Carter [this message]
2017-01-21 17:05 ` Stephen Leake
2017-01-22 5:12 ` Robert Eachus
2017-01-23 8:02 ` G.B.
2017-01-23 8:19 ` Simon Wright
2017-01-21 18:55 ` b.mcguinness747
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox