[fpc-pascal] Re: Ideas for namespace implementation

Martin fpc at mfriebe.de
Mon Jul 26 16:47:27 CEST 2010

On 26/07/2010 15:36, Marcos Douglas wrote:
> On Mon, Jul 26, 2010 at 11:20 AM, Sven Barth
> <pascaldragon at googlemail.com>  wrote:
>> What about that the compiler enforces that you use the fully qualified name
>> if you used it in the uses?
> Not only if you used it in the uses clause, but if you COMPILED with
> namespace sintaxe (eg. by Graeme unit strutils namespace my), IMHO...
> But we would have a problem stated by Michael:
> On Mon, Jul 26, 2010 at 6:34 AM, Michael Van Canneyt
> <michael at freepascal.org>  wrote:
>> Well, I fail to see what is more logical in my.constants than in
>> myconstants.
>> The unit is still called my.constants, not constants. So you'll end up
>> typing my.constants everywhere anyway. The gain of this over myconstants is
>> highly debatable.
Yhat is the point I was trying to make.

If I understand correctly, Graeme wants namespace, so the 
prefix/namespace could be left away => resulting in shorter and 
depending on personal taste better looking names.
I believe Graeme explicitly stated, that he wants to use "utils" and not 
"graemeutils" in his code.

But, exactly that is the problem. If you allow the same (same, if not 
fully qualified) identifier, for different things, then it makes the 
source unreadable (obfuscated).

And yes, it was said, there are already rules for resolving names. And 
some more or less make no different: They may make no different to a 
piece of software, like the compiler => the compiler can resolve the 
rules in a blink. But humans can not, and humans are error prone.
Deliberately encouraging ambiguous names, is (as far as human 
readability goes) a really bad thing.

And so that leaves to enforce full qulification always. => which is 
true, makes the need for namespaces redundant. It makes no diff if it 
always is:
myutils or my.utils
The dot increasing the readability => but so would an underscore my_utils.
The _ may be frowned up on, but that does not mean there is a technical 
issue with it, it's simple a style. And if the dot would be allowed, 
then it was no better than the underscore, it could quite quickly be 
frowned up on too?

> So... maybe create a new directive like as {$NAMESPACE ON}
> eg.
> unit strutils namespace my;
> With {$NAMESPACE ON} all units will have namespaces, unless FPC's units.
Not sure why a directive?

To allow none fully qualified names? Then we a back to square one.

More information about the fpc-pascal mailing list