[comp.lang.misc] subranges

diamond@csl.sony.co.jp (Norman Diamond) (10/30/89)

In article <11012@riks.csl.sony.co.jp> I wrote:

[Regarding PL/I precisions vs. newer languages' integer subranges]
>>I'd say this case [application programming] is much harder.
>>Wirth got this one right.

In article <31141@news.Think.COM> barmar@kulla (Barry Margolin) writes:

>You keep saying this.  Wirth has designed at least two languages; which one
>are you talking about?  Pascal and Modula-2 both have range types,

Yes I'm talking about these two, as well as Ada, Eiffel, etc.

>which
>are very similar to PL/I's precision option.  FIXED BIN (n) is the same as
>the range -2^n .. 2^n-1, and FIXED BIN (n) UNSIGNED is like 0 .. 2^n-1.

Yes, but people don't usually go hunting for a nearby power of 2 to
use instead of what they really want.

Here's what's usually done:

CONST My_lower_bound = 53;
CONST My_upper_bound = 11532;
TYPE  My_index_T = My_lower_bound .. My_upper_bound;
TYPE  My_array_T = ARRAY [My_index_T] OF CHAR;
TYPE  My_counter_T = 0 .. (My_upper_bound - My_lower_bound + 1);

VAR   My_first_list : My_array_T;
VAR   My_head_index : My_index_T;
VAR   My_tail_index : My_index_T;
VAR   My_counter    : My_counter_T;

>Yes, the newer languages permit you to specify more specific ranges,

and to use named constants so that you only specify the numbers once,
and you specify exactly what number you want; you don't have to figure
out powers of 2 or log-base-2's before you code your datatypes.

>but
>they're generally implemented the same as the above two classes of types.

Of course.  They're implemented in units that the hardware has circuitry
for.  What does this have to do with maintainability?  Only if the
programmer (e.g. C programmer) has to know the hardware units, then it
is a nuisance.  (This comment does not address system programming; I
think we already agreed on that case.)

>You have the same problem with overflow as in PL/I.

And the same as in any language.  If you're afraid of overflows, maybe
you'd better change your profession.

>What PL/I is really missing is user-defined types.

And named constants and built-in ceiling-of-log-base-2 at compile time,
eh?  Well, it seems to me that
  53 .. 11532
is easier to read than
  PREC(CEIL(LOG2(MAX(-53,0)+MAX(0,11532)+1)))

-- 
Norman Diamond, Sony Corp. (diamond%ws.sony.junet@uunet.uu.net seems to work)
  Should the preceding opinions be caught or     |  James Bond asked his
  killed, the sender will disavow all knowledge  |  ATT rep for a source
  of their activities or whereabouts.            |  licence to "kill".