comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not>
Subject: Re: Looking for feedback: ISO 3166-1 country Country Code Reference in Ada
Date: Mon, 17 Apr 2023 11:36:53 +0200	[thread overview]
Message-ID: <u1j3vm$2va2c$1@dont-email.me> (raw)
In-Reply-To: <1fdb945b-fc6d-41dd-9c27-41a7fe9019fdn@googlegroups.com>

On 2023-04-15 20:52, A.J. wrote:
> I just created a library for accessing ISO 3166-1 records in Ada compatible with Ada.Locales. Before I try to publish it to Alire, I'm hoping to get some feedback if anyone has some. It's possible that feedback will result in the function calls, naming convention, or structure being set up differently, so please let me know what you think.
> 
> https://github.com/AJ-Ianozi/iso_3166

Some initial thoughts on what you have:

It seems likely that your clients will use the alpha codes for input and 
display. It will be more convenient for that if the alpha codes are subtypes of 
String rather than distinct types.

Since you have already enumerated all 250 possible alpha codes, your predicates 
could look like

subtype Alpha_Code_2 is String (1 .. 2) with
    Dynamic_Predicate => Alpha_Code_2 in "AF" | "AL" | ...;

and similar for the 3-letter codes.

Since you have already enumerated all 250 possible numeric codes, you could use 
a restricted range for your numeric (sub)type, with a predicate restricting it 
to valid values.

These use the language to do validity checking for you.

Regarding the design of such a pkg, my initial instinct was to use enumeration 
types for the alpha codes, but a little investigation shows that some of the 
codes are Ada reserved words, so that doesn't work. So I would stick with the 
String subtypes and provide functions such that, given one of the values, the 
client can obtain the others, as well as the name. Alternatively, one could have 
functions to return a record such as you provide. Which is preferable depends on 
how such a pkg is typically used.

There are various possible implementations, with different tradeoffs.

-- 
Jeff Carter
"He nevere yet no vileynye ne sayde
In al his lyf unto no maner wight."
Canterbury Tales
156

      reply	other threads:[~2023-04-17  9:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-15 18:52 Looking for feedback: ISO 3166-1 country Country Code Reference in Ada A.J.
2023-04-17  9:36 ` Jeffrey R.Carter [this message]
replies disabled

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