[fpc-pascal] Re: [Bulk] Re: Namespaces Support

Marcos Douglas md at delfire.net
Wed Oct 30 18:58:11 CET 2013


On Tue, Oct 29, 2013 at 5:05 PM, Dmitry Boyarintsev
<skalogryz.lists at gmail.com> wrote:
> On Tue, Oct 29, 2013 at 3:50 PM, Marcos Douglas <md at delfire.net> wrote:
>>
>> Yes, works... but the language allow hide the unit name and nobody
>> uses unit name as an identifier in 99% of cases, Am I right? So,
>> problems can be happen.
>>
> From my experience I'd say no.
> I actually had to use the explicit unit name in probably 2% of the code.
> Back from Delphi days: some of the functions between WinAPI (windows.pas)
> and VCL (sysutils.pas) are actually using the same name.
> So specifying the exact unit name is required to get the code compiled
> properly.
> There were some collisions on MacOSX (carbon) type names with LCL type
> names.
> So it's not that unrare thing to happen.
>
> And as you've given example above. If I'm writing a unit that uses two
> separate units with the same identifiers reused, I'd recommend to specify a
> unit name explicitly. (Just not to rely on a compiler doing it right for
> you).
> uses
>   windows, graphics;
>
> var
>   wb : Windows.TBitmap;
>   gb : Graphics.TBitmap.
>
> or
>
> uses
>   windows, graphics;
>
> type  // declare once, use everywhere
>   TWindowsBitmap = Windows.TBitmap;
>   TGraphicsBitmap = Graphics.TBitmap;
>
>
> var
>   wb : TWindowsBitmap;
>   gb : TGraphicsBitmap.
>
> thanks,
> Dmitry

Yep, this is a good tip if you have a couple of types and works.
But, if you have two or more units that have many types and/or
functions that have the same name, then this job -- create an alias --
is boring. I had this problem just one time in my life, I confess, but
happened.

But, little collisions happen easily -- using procedures/functions is
more easy -- because, as you said, we only use the unit name as a
prefix (2% code) only if we know, previously, that we should use.

I guess I will not convince you, right? :)
That's Ok.

Regards,
Marcos Douglas



More information about the fpc-pascal mailing list