Re: [BLACKBOX] IN Parameters - Making the design more regular

From: [at]} <CFB>
Date: Thu, 31 Jan 2008 10:45:41 +1030

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

> -----Original Message-----
> From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
> Sent: Thursday, 31 January 2008 5:20 AM
> To: BLACKBOX{([at]})nowhere.xy
> Subject: Re: [BLACKBOX] IN Parameters - Making the design more regular
>
> Hi Chris,
>
> After your latest explanations I rethought my arguments and
> looked a your
> example(s. below):
>
>
> In this case I cannot see a big advantage of x being an IN
> parameter of
> procedure P because the writer of procedure P ( and
> consequently procedure
> SomeOtherProcedure) should and hopefully does know the value of x as
> he/she is the only one having been able to modify the value
> of the local
> variable x,

Yes - that would be true if:

 a) you are working on a small non-complex module AND
 b) you are working on code you developed *recently* AND
 c) you are the original and only author of all of the code in that module

If, however, you are working on a complex module, that you didn't originally
develop yourself that contains thousands of lines (one of the modules of the
BlackBox compiler for example?) then the benefit of the use of IN parameters
becomes more obvious.

In the example

> PROCEDURE P(x: INTEGER);
> BEGIN
> ...
> SomeOtherProcedure(x);
> ...
> (* Who knows what the value of x is? *)

whether or not x still has its original value after the call to
SomeOtherProcedure depends on whether the declaration of SomeOtherProcedure
is:

  PROCEDURE SomeOtherProcedure(x: INTEGER);

  PROCEDURE SomeOtherProcedure(IN x: INTEGER);

  PROCEDURE SomeOtherProcedure(OUT x: INTEGER);

  PROCEDURE SomeOtherProcedure(VAR x: INTEGER);

To find out you have to go looking for the declaration of
SomeOtherProcedure, thus breaking your reading flow and perhaps losing your
place in the source.

Now if the outer procedure is declared as

  PROCEDURE P(IN x: INTEGER)

then you don't need to check. The declaration of SomeOtherProcedure could
not have been one of the latter two declarations otherwise the code just
would not have compiled. As you know it must have been one of the first two
declarations then you can be 100% certain that x remains unchanged.

e.g.

PROCEDURE SomeOtherProcedure(VAR x: INTEGER);
...
(* Many thousands of lines of code *)
...
PROCEDURE P(IN x: INTEGER);
...
...
  SomeOtherProcedure(x) --> ERROR: This variable (field) is read only
...
...

> The real advantage of IN parameters for me shows up when it comes to
> interfaces i.e. exported procedures. Here your proposal to
> allow this
> keyword for all variable types would indeed on one hand make
> the language
> more "regular" as you said, on the other hand, more important
> I believe,
> safer as the caller of an otherwise unknown procedure from an
> imported
> module can be shure the value of x will be unaltered after procedure
> execution, which certainly improves code reliability.

Exactly! Thanks for pointing that out. In retrospect, I would have made my
point much clearer if I had said:

> > Consider this code:
> > PROCEDURE P(x: INTEGER);
> > BEGIN
> > ...
> > SomeOtherModule.SomeOtherProcedure(x);
> > ...
> > (* Who knows what the value of x is? *)


>
> > The way I have implemented it should generate identical code.

>
> look quite convincing and if this is so I happily withdraw my
> objections
> gratefully relying on the compiler writer (which I am not).
>

I have to say that I am only 99% certain - that is why I appreciate the
feedback - just in case I overlooked something obvious. The solution was so
easy to implement I could not help wondering why it was not implemented that
way in the first place. Either I am making a fundamentally wrong assumption,
or maybe the implementers were unable to 'see the forest for the trees'.

Maybe by describing the steps involved in parsing the declaration of IN
parameters somebody might be able to tell me if there is a flaw in my logic:

1. At the point of parsing the declaration:

  PROCEDURE P(IN x: ....

BlackBox records that x is a 'var' parameter with the additional attribute
that it is readonly.

I record that x is a 'value' parameter with the additional attribute that it
is readonly.


2a. If further parsing reveals

  PROCEDURE P(IN x: INTEGER) ....

I record that x is of type integer and proceed as if x had been declared as
a value parameter.

BlackBox gives an compilation error saying that x should be an array or
record type.


2b. If however, further parsing reveals

  PROCEDURE P(IN x: SomeRecordOrArrayType) ....

I record that x is SomeRecordOrArrayType and redefine x as 'var' parameter.
Further processing is identical to BlackBox.

BlackBox records that x is SomeRecordOrArrayType.

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

Regards,
Chris

Chris Burrows
CFB Software
http://www.cfbsoftware.com/cp


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-2027486574_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
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g0K
SSByZWNvcmQgdGhhdCB4IGlzIFNvbWVSZWNvcmRPckFycmF5VHlwZSBhbmQgcmVkZWZpbmUgeCBh
cyAndmFyJyBwYXJhbWV0ZXIuXHBhcg0KRnVydGhlciBwcm9jZXNzaW5nIGlzIGlkZW50aWNhbCB0
byBCbGFja0JveC5ccGFyDQpccGFyDQpCbGFja0JveCByZWNvcmRzIHRoYXQgeCBpcyBTb21lUmVj
b3JkT3JBcnJheVR5cGUuXHBhcg0KXHBhcg0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLVxwYXIN
ClxwYXINClJlZ2FyZHMsXHBhcg0KQ2hyaXNccGFyDQpccGFyDQpDaHJpcyBCdXJyb3dzXHBhcg0K
Q0ZCIFNvZnR3YXJlXHBhcg0KaHR0cDovL3d3dy5jZmJzb2Z0d2FyZS5jb20vY3BccGFyDQpccGFy
DQpccGFyDQotLS0tXHBhcg0KVG8gdW5zdWJzY3JpYmUsIHNlbmQgYSBtZXNzYWdlIHdpdGggYm9k
eSAiU0lHTk9GRiBCTEFDS0JPWCIgdG8gTElTVFNFUlZATElTVFMuT0JFUk9OLkNIfX0AR0Z5RA==
----boundary-LibPST-iamunique-2027486574_-_---
Received on Thu Jan 31 2008 - 01:15:41 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:31:05 UTC