[fpc-pascal] Re: Ideas for namespace implementation

Marcos Douglas md at delfire.net
Mon Jul 26 16:23:31 CEST 2010


On Mon, Jul 26, 2010 at 11:20 AM, Sven Barth
<pascaldragon at googlemail.com> wrote:
> Hi!
>
> On 26.07.2010 16:06, Martin wrote:
>>>>
>>>> But worst of all
>>>> uses sysutils; // the one from my project?
>>>
>>> No, because the RTL is not compiled with a namespace, so falls under the
>>> "global" namespace with takes preference over project units or all other
>>> namespaces. This then stays consistent with how developers understood the
>>> code as it currently works. Compiler included units take preference.
>>
>> You missed the important bit of this section.
>>
>> let's correct the uses:
>>
>> uses myspace.sysutils;
>> // and only this sysutils, not using the global rtl.sysutils at all
>> ....
>> begin
>> SysUtils.Exception;
>>
>> Now if any one else is to read/review/... the code => they will not be
>> aware of sysutils not being rtl.
>> They will assume that "SysUtils.Exception" is "RTL.SysUtils.Exception",
>> but it really is "myspace.SysUtils.Exception"
>>
>> For me,. that is code obfuscation. 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.
>>
>> But if we allow the unqualified to only refer to the original rtl one =>
>> then all other SysUtils must be fully qualified at any occurence they
>> have (even if they are the only SysUtils used in that unit).
>> And if the always need full qualification, then they do not differ from
>> a prefix (the dot becomes part of the unti name).
>
> What about that the compiler enforces that you use the fully qualified name
> if you used it in the uses?
>
> e.g.
>
> uses
>  myspace.sysutils; // this sysutils contains an identifier "Exception"
>
> begin
>  Exception; // no error
>  SysUtils.Exception; // identifier not found
>  MySpace.SysUtils.Exception; // no error
> end.
>
> So the declaration of "myspace.sysutils" declares a new pseude-identifier.
> By using a different separator or prefix this could be made even less
> problematic for "new users/readers" (I'll chose "~" now for the sake of
> example):
>
> uses
>  myspace~sysutils;
>
> begin
>  Exception; // no error
>  SysUtils.Exception; // identifier not found
>  MySpace~SysUtils.Exception; // no error
> end.
>
> With RTL's sysutils:
>
> uses
>  sysutils, myspace~sysutils;
>
> begin
>  Exception; // normal resolution of duplicated types, so sysutils wins (or
> does the last one win? - I can't remember now...) => no error
>  SysUtils.Exception // the RTL's Exception
>  MySpace~SysUtils.Exception; // Exception from MySpace~SysUtils
> end.
>
> Hmm... "~" looks ugly :P

IMHO, is better to use the ':' like  myspace:sysutils

uses
  myspace:sysutils;

begin
  Exception; // no error
  SysUtils.Exception; // identifier not found
  MySpace:SysUtils.Exception; // no error
end.


MD



More information about the fpc-pascal mailing list