[fpc-pascal] dot within unit file name

Marco van de Voort marcov at stack.nl
Fri Jan 18 14:35:53 CET 2008


> Michael Van Canneyt wrote:
> > On Fri, 18 Jan 2008, Matt Emson wrote:
> > What is the difference ? 
> > The second one saves on typing, which is a plus in my book ?
> >   
> Right.. confusion over verbosity. Given two units called 
> "Constants.pas", which one is the correct unit?

Give two the same classes in the same namespace, which one is chosen?

> Given a unit called "Utils.pas" and one called "ExtraDefs.pas", both of
> which contain different implementations of the type TSocket, which is the
> correct unit to use?

Utils.TSocket or ExtraDefs.TSocket.

> >> unit Blah;
> >> Namespace MyAPI.Blah;
> >
> > And how will you know which namespace is in what unit (or file) ?
> >   
> 
> Turning it on its head - file names should have nothing to do with unit 
> names.

That means either that you must scan all files in all dirs to build your
state, or must register een unit (cq class) before using it, so that the
compiler can limit the space. (this "registration" system can be a directory
structure, but IMHO is replacing a fixed filename with a fixed dirname is no
solution either)

This is exactly what the unit system was designed to avoid, central
registries of units/classes. Under Java/.NET you need this because the JIT
must be able to find them runtime too. With normal compilation this is a
burden.

> unit Blah;
> namespace MyAPI
> 
> uses MyAPI.Blah;

And all this to avoid double unit names. Which is way less of a problem,
since you have multiple classes in an unit (namespace) as a feature.

> > You then need a second structure mapping namespaces on filenames, making it
> > slower, bulkier and error prone. The cure is worse than the disease, IMHO
> 
> Nope.. see above.
> 
> Do you have a problem with partial classes? Also called "Categories" in 
> Objective C.

I don't like the concept, but for some workarounds it can be of some use in quick 'n
dirty hacks. All in the case where you don't want to change libs as a
temporary workaround (e.g. if they have to be revalidated with other apps
then too)

However again, as far as I understand partial classes (Class
Helpers in Delphi.NET), for this you need a registration system again because you need
to compile all units that might use class X so that they auto import all
units with classhelpers for unit X. (or you have to scan all directories
on each compiler start, and must make 100% sure that you don't use units
that don't have these class helpers added.




More information about the fpc-pascal mailing list