Re: [BLACKBOX] SYSTEM.VAL, WITH, IS, and type casting

From: [at]} <Bob>
Date: Mon, 22 Aug 2011 08:34:14 +0100


> The fact that one can get away with using SYSTEM.VAL says to me that
> there is a flaw in Component Pascal (but please argue this point).

> Why not just do
> m := a
> and let the run time system determine whether or not "a IS MyObject"?

 

If I've understood you correctly, your version would lead to a runtime error if ~ (a IS MyObject), whereas the other version would lead to a compile-time error and is therefore safer.

 

The use of SYSTEM.VAL and explicit typecasting is your way of telling both the compiler and later programmers who have to maintain your code that you were aware of what you were doing, and did it deliberately.

 

This is one of the things that distinguishes Wirthian languages from stuff like BASIC, which let you make all sorts of errors which you don't learn about until runtime (or later) when you have the least time to correct it, and the corrections - if they are possible - are most expensive.

 

B

 

From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
Sent: 22 August 2011 08:23
To: BLACKBOX{([at]})nowhere.xy
Subject: [BLACKBOX] SYSTEM.VAL, WITH, IS, and type casting

 

In Stores I find

    PROCEDURE (VAR rd: Reader) ReadSChar* (OUT x: SHORTCHAR), NEW;
    BEGIN
        rd.rider.ReadByte(SYSTEM.VAL(BYTE, x))
    END ReadSChar;

That is a strange strategy!

But consider this
PROCEDURE Proc(OUT x: AbstractObject); ... END Proc;

and

VAR m: MyObject;
Proc(SYSTEM.VAL(AbstractObject, m));

That works and uses fewer steps than

VAR a: AbstractObject;
Proc(a);
WITH a: MyObject DO ... END;

or

VAR m: MyObject; a: AbstractObject;
Proc(a);
m := a(MyObject);

The fact that one can get away with using SYSTEM.VAL says to me that
there is a flaw in Component Pascal (but please argue this point).

Why not just do
m := a
and let the run time system determine whether or not "a IS MyObject"?
One could then also just write
Proc(m)
without any explicit type casting.

It would also be nice to be able to write
rd.ReadStore(m)
rather than
rd.ReadStore(store); m := store(MyObject);

Is the reason for explicit type cast to say "what you see is what you get"? or
is there some other reason that I have over looked?

-Doug Danforth

---- To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy

---- To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy
Received on Mon Aug 22 2011 - 09:34:14 UTC

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