Re: Named Integers

From: [at]} <Stan>
Date: Sat, 20 Nov 2004 13:34:17 -0800

----boundary-LibPST-iamunique-1522719106_-_-
Content-type: text/plain

> Stan,
>
> I'm curious. What would the characteristics of the proposed "named
> integers"
> be? What would be an example of their use? How would they differ from
> integer CONST?
>
> Chris Burrows
> CFB Software
> http://www.cfbsoftware.com/gpcp
>
>> OK. That answers my question. I see your points about the impact
>> of complexity on your code. I periodically request "named integers"
>> for CP, which would give 90% of the benefits of enumerated types
>> with 10% of the implementation cost. But the complexity of using
>> integer CONST without "named integers" is not nearly the complexity
>> you would have to endure without procedure variables.
>>
>> Thanks,
>> Stan

The benefit of named integers is self-documentation. On the surface,
they look like enumerated types, but they are fundamentally different
because they do not have the implementation problems of type
checking that enumerated types have. Hence, you get 90% of the
benefits of enumerated types with 10% of the implementation cost.

Here is an example. In the documentation for Module Ports, we have

CONST
    invert = 0; hilite = 1; dim25 = 2; dim50 = 3; dim75 = 4;

Then, later in the documentation we have

(f: Frame) MarkRect (l, t, r, b, s: INTEGER; mode: INTEGER; show:
BOOLEAN), NEW;

Then, still later in the documentation, we have this explanation

CONST invert, hilite, dim25, dim50, dim75
These values may be passed as mode-parameter to procedure MarkRect.

The parameter list of MarkRect is _not_ self-documenting. All you know
by looking at formal parameter mode is that it is an integer. All you
know
by looking at the CONST section is that there are some integer
constants,
but you have no way of knowing which of the integer constants, if any,
is meant to be used as the mode value in MarkRect. You must search
through
the documentation for the explanation.

Named integers would work like this.

TYPE
    MarkMode = (invert, hilite, dim25, dim50, dim75);

(f: Frame) MarkRect (l, t, r, b, s: INTEGER; mode: MarkMode; show:
BOOLEAN), NEW;

Although the syntax looks like the syntax of enumerated types, named
integers are _not_ enumerated types. As I understand it, 90% of the
difficulty of implementing enumerated types is the type checking that
must
occur across modules. The implementation difficulty was so severe that
enumerated types were not included in the definition of CP.

Named integers have none of the implementation problems of enumerated
types. They are simply a syntactic sugar that provide an immense benefit
of self-documentation for a very small price. They do not introduce a
new
type. Named integers _are_ integers. In general

TYPE Alpha = (beta, gamma, delta);

is _defined_ to be exactly equivalent to

TYPE Alpha = INTEGER;
CONST beta = 0; gamma = 1; delta = 2;

As far as export is concerned

TYPE Alpha* = (beta, gamma, delta);

is defined to be equivalent to

TYPE Alpha* = INTEGER;
CONST beta* = 0; gamma* = 1; delta* = 2;

There is no need for complex type-checking rules with enumerated values
as there is in C++. gamma _is_ an INTEGER and can be used anywhere an
integer can be used. mode is still an INTEGER. Named integers would
change
_nothing_ in the implementation of the entire BlackBox framework except
for
making the interfaces much easier to read.

When I was first learning the BB framework I was used to software design
that emphasized enumerated types for self-documentation. It was a source
of irritation to see an integer parameter in a formal parameter list
and not
know immediately which set of integer constants applied to it. I think
one
reason it has been a hard sell to the folks at Oberon microsystems is
that
they are so familiar with the framework that they forget what it is
like for
a novice to be learning BB for the first time.

Stan

J. Stanley Warford
Professor of Computer Science
Pepperdine University
Malibu, CA 90263
Stan.Warford{([at]})nowhere.xy
310-506-4332

--------------------------------------------

To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
   blackbox-request{([at]})nowhere.xy

To get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.

Send any problem reports or questions related to this email list to the list owner at
   owner-blackbox{([at]})nowhere.xy

Current posting policy:

a) To post you should use the same address by which you are subscribed to the mailing list. That way, the list server will recognize you as subscriber and forward your posting immediately, without creating any overhead.

b) If, for some reason, you cannot post from the address, by which you are subscribed, your message will be moderated to avoid spam. Please understand that moderation will often cause some delay, in particular over weekends or holydays.


----boundary-LibPST-iamunique-1522719106_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ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2lkIHNwYW0u
IFBsZWFzZSB1bmRlcnN0YW5kIHRoYXQgbW9kZXJhdGlvbiB3aWxsIG9mdGVuIGNhdXNlIHNvbWUg
ZGVsYXksIGluIHBhcnRpY3VsYXIgb3ZlciB3ZWVrZW5kcyBvciBob2x5ZGF5fX0AZGF5cy4K


----boundary-LibPST-iamunique-1522719106_-_---
Received on Sat Nov 20 2004 - 22:34:17 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:28:30 UTC