----boundary-LibPST-iamunique-1135550597_-_-
Content-type: text/plain
Thanks, Marc. I guess naming conventions (e.g., Hungarian notation)
are indeed the state of the art. Since compilers are no help here, it
forces the user to keep careful track of whether an array is implemented as
a pointer or a static variable. It also occurs to me that compilers could
easily help to keep track of this.
Gérard and Wojtek, I understand perfectly why my example gives
unexpected results. That's why I wrote it. Identical-appearing statements
can give you very different results, depending on whether an array is static
or dynamic. I just realized it gets worse: the results also depend on state.
Yes, the type declaration will help you if you don't make a mistake.
Compilers are supposed to be good at catching that kind of mistake, but in
this case they don't. If it's not obvious by now, consider the following.
VAR a, b: POINTER TO ARRAY OF INTEGER;
PROCEDURE DoSomething;
BEGIN
b[1] := 1;
IF something THEN
b := a END:
b[1] := 1;
END DoSomething;
In general, the results of b[1] := 1 cannot be determined at compile time.
We don't even know whether the other b[1] := 1 statement does the same thing!
Now if you happen to have another procedure:
PROCEDURE DoSomethingElse;
BEGIN b := .... END DoSomethingElse;
you're cooked. The results are likely to be unpredictable, and the
nightmarish side effects may extend to variable a -- and all because maybe
you forgot whether a and b are static or dynamic.
After thinking about it some more, if I were designing a language, I
think I might forbid assigning a pointer except with a predefined procedure.
For example:
VAR a, b: POINTER TO ARRAY OF INTEGER;
...
b := a; (* forbidden *)
ASSIGN (b, a); (* allowed *)
That is certainly one way of alerting you to a dynamic array and keeping you
from making a pointer assignment by mistake. I haven't thought much about
it, but I don't see any obvious problem with it.
Frankly, I don't much like one variable inadvertently being aliased
to another. Wouldn't it be nice if we didn't have to remember whether an
array is implemented as a pointer or a static variable? Too bad compilers
don't keep track of this sort of thing.
I was hoping someone had some sort of magic. Since they don't, I'm
sticking to old-fashioned Hungarian notation.
Rex Couture
--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy
----boundary-LibPST-iamunique-1135550597_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvb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