🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1092

Re: name space proposal ("with" statement)

#1092
From: Garry Wiegand
Date: Mon, 13 May 1991 22:06
68 lines
2953 bytes
In a recent article keithro@microsoft.UUCP (Keith ROWE) wrote:
>main()
>{
>	use Microsoft;
[a number of statements]
>	tallyWindow(myWindow);
>}

A few comments. The "use Microsoft" statement in the above is sort
of weird - it looks like it might be a declaration statement, but
"use" is an active verb and for me makes the statement look more
like an executable. Also, the style is perhaps surprise-inducing -
"use Microsoft" is an innocuous-looking statement buried among
others but it has unusually subtle and drastic effects. It makes me
think of #include's and goto's.

I don't know if this has been discussed, but how about the
traditional (in Algol/Pascal/PL1/etc worlds) 'with' construct
instead? The C/C++ version would be something like:

    with (blah) {
    }

meaning "please try to disambiguate the names in this block in favor
of the 'blah' context". 

The classical example of this style is structure references - the
following simple code:

    struct {float x,y;}   *vector;
    ...
    cout << "Length is" <<
    	sqrt(vector->x*vector->x + vector->y*vector->y);

would also be expressable as:

    struct {float x,y;}   *vector;
    ...
    with (*vector) {
    	cout << "Length is" << sqrt (x*x + y*y);
    }

(or of course:)

    with (*vector) cout << "Length is" << sqrt (x*x + y*y);

The block would follow the usual scoping conventions. The wonderful
C++ disambiguation rules would have to be worked out. The syntax for
Keith's case would be "with (Microsoft) { }". 

There is an example of the concept already in the language: method
bodies behave exactly as if they were surrounded by a "with (*this) { }".
It would be nice to have it available for things other than "*this".
(I admit that if you can write your class definitions real cleanly
you might scarcely *need* it for cases other than "*this".) 

So: I agree that C++ names are getting complicated, and I claim that
a new general construct that could help you organize the name
references would be a good thing to have. In particular, a 'with'
would get you more value for your syntactic money than a 'use'
because it would also be meaningful for structure references and for
all types of '::' references. It would offer a reasonable hint to
the compiler that when the appropriate the operand might be worth
optimizing into a register. The 'Name::' dereferencing Keith needed
would come almost for free as part of a more general concept. 
 
Garry Wiegand --- Ithaca Software, Alameda, California
...!uunet!ithaca!garry, garry%ithaca.uucp@uunet.uu.net
Technical Details
Message-ID: <1991May13.220635.4601@ithaca.uucp>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!ithaca!garry

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!ithaca!garry
From: garry@ithaca.uucp (Garry Wiegand)
Newsgroups: comp.std.c++
Subject: Re: name space proposal ("with" statement)
Message-ID: <1991May13.220635.4601@ithaca.uucp>
Date: 13 May 91 22:06:35 GMT
Organization: Ithaca Software
Lines: 68