[fpc-pascal] Namespaces Support

Michael Van Canneyt michael at freepascal.org
Fri Oct 25 09:35:45 CEST 2013



On Fri, 25 Oct 2013, Marco van de Voort wrote:

> In our previous episode, Fabr?cio Srdic said:
>>
>> e.g types -> system.types; winsock -> windows.winsock; winmouse ->
>> windows.winmouse
>
> Delphi uses winapi, not windows.
>
> And I see no need. There is so much code in use that assumes the standard
> names, and I don't see a need to force existing codebase users to rename
> everything just to free up a few unit names for packages that are
> essentially free to chose their own.

There is a need. Without it, you will severely cripple the use of default namespaces.

If someone 
* defines a namespace 'mycompany', 
* uses that namespace as the default namespace
* has a 'classes' unit (or anything else that name-clashes with our units) in that namespace
   he/she will never be able to use our classes unit again.

This is not so far-fetched as it may seem, becaus this kind of thing is exactly why namespaces 
were invented, so you CAN choose your names to match FPC unit names. So people that use namespaces
are likely to do so.

So you have something like

{$NAMESPACE MyCompany}
uses Classes; // Adds MyCompany.Classes

So, how to add our own classes unit to the uses clause ?

You can probably work your way around it, but if the FPC distributed units have namespaces, 
there is no problem.

I'm not necessarily advocating this, but it seems to me that if you enable use of namespaces, 
putting all FPC units in appropriate namespaces is the logical and consequent thing to do.

Michael.



More information about the fpc-pascal mailing list