[fpc-pascal] Re: Ideas for namespace implementation

Martin fpc at mfriebe.de
Mon Jul 26 14:34:40 CEST 2010

On 25/07/2010 22:53, Graeme Geldenhuys wrote:
> On 25 July 2010 23:30, Michael Van Canneyt wrote:
>> The discussion is not about namespaces. Object Pascal HAS namespaces,
>> namely units. The discussion is about 'enhancing' the namespace to allow one
>> or more dots in the name.
> With the importance that the '.' is only needed when resolving a
> conflict - all other instances, you will just use the unit name as
> normal. Also, the '.' usage is only limited to the uses clause. At
> least we will be able to easily use more logical unit names without
> the fear of getting unit name conflicts.
Let me see, if I got the idea (Graeme's idea) correct.

lets say we have:
rtl:   classes, sysutils,  but *not* foo
rxlib:   sysutils, foo    (all in namespace rx)
mylib:   foo   (namespace my)
It the my project itself:   sysutils, my   (no namespace?)

uses classes;    // the one from rtl
uses sysutils;    // the one from my project?
uses rtl.sysutols;   // rtl
uses foo;  // error ambigious?
uses rx.foo;  // rxlib

Am I correct so far, that his is the plan?

uses rc.foo, my.foo, my; // there is a unit my
   foo.a; // error, which foo?
   my.foo.a; // is that unit my, record foo.a OR unit my.foo ?

But worst of all
uses sysutils;    // the one from my project?

Now if any one else is to read/review/... the code => they will not be 
aware of sysutils not being rtl.
In order to keep it human understandable, the unt name "sysutils" 
(unqualified) must only be allowed to refer to exactly one unit => the 
one from the rtl, no other one ever.

uses rs.sysutils
sysutils.a; // againg, it is "sysutils" onlt, any reader should be 
correct to think it is from the rtl and the rtl only

if sysutils ever refers to anything but the rtl, it will (highly) 
obfuscate the code.

or "foo" in the above example.

let's say it wasn't part of rx. And my project uses the packages rx and 
my. then
uses foo; // from package my, since it only exists there.

Nor rx is updated, and suddenly contains a unit called "foo" => and all 
code breaks
Well it would break without namespaces too, but still namespaces hasn't 
helped avoiding the breakage.

Yes, maybe in this case namespaces can help fixing the breakage, but at 
the cost of code obfuscation...

More information about the fpc-pascal mailing list