[fpc-devel] Re: [fpc-pascal] Re: Ideas for namespace implementation
pascaldragon at googlemail.com
Mon Jul 26 17:34:14 CEST 2010
On 26.07.2010 17:18, Martin wrote:
> On 26/07/2010 15:55, Sven Barth wrote:
>> So... continuing the thread were it belongs... in fpc-devel :P
>> On 26.07.2010 16: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...
>> The whole idea is to compile units with a namespace not just using on
>> in the uses because it's funny.
>> Either its compiled by including "namespace Foo" in the units
>> themselves or by using a commandline parameter "-namespace Foo", so
>> that not every unit needs so be changed (both modes are supported and
>> the "in unit" version takes precedence of the commandline one).
>>> 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
>>>> 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.
>> It's not about not having to type the "fully qualified name", but
>> about not having to rename/prefix my own units, because they conflict
>> with an existing unit.
> Ok, so that means:
> If refering to the unit, or any element in it, you always have to use
> the full namespace:
> uses my.utils;
> var a: my.utils.TFoo;
> that is, inside the unit that uses the other unit, the other units name
> is effectively "my.utils" => with the dot being part of the name
> If writing a unit, that is to be in a namespace you can do
> unit utils namespace my;
> but that is no different from doing
> unit my.utils;
Not exactly, because
"unit utils namespace my" resides in "utils.pas"
"unit my.utils" resides in "my.utils.pas" (Delphi compatible).
(no usage of compiler switch -Un here)
You can still do a
with the namespace approach. The namespace-identifier is only needed if
you want/need to avoid a conflict.
> *** up to this point, there is no difference to using a prefix on the
> unit name? "unit MyUtils" ***
> The new thing is that you are allowed to give the namespace on the
> commandline, effectively allowing to change it without needing to change
> all of the sources
> But that can be done for prefixes too:
> fpc -unitprefix=My Utils.pas
In theory, yes, but Delphi allows more than one prefix for the unit name
Except you regard the complete sequence up to the last point in the unit
name as prefix... but it's still not exactly the same because of the
reasons mentioned above.
> It acts like a pre-processor, it will find the unit declaration, and
> prefix the unit name...
Not really. The namespace will be saved in the ppu as an extra field in
both usages (in unit vs command line). So you can still use "utils"
without the "my"-Prefix/Namespace (see above).
> So no fancy-new and introducing-problems (ambiguity mu.utils.a => unit
> my; record utils) issue....
> In fact if the existing
> uses Foo in 'dir';
> could be extended to allow a package or similar
> uses Foo in 'LCL'
> and an alias directive would be introduced, then it was all solved too
> uses Foo in 'lcl' alias 'FooLCL', Foo in 'RTL' alias 'FooRTL'
That would be another possibilty (and might be added as an alternate
idea to this discussion ^^), but currently this "in"-syntax is
restricted to the "program"/"library" file.
More information about the fpc-devel