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
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)