Hi!

I personally don't have a real opinion pro or against extended namespace, so I'll try to answer as neutral as possible.

Am 25.07.2010 19:45, schrieb Graeme Geldenhuys:
1)  Follow the "dotted" notation for unit names as implemented in Delphi.
    (...)


2) Another idea is in a way similar to how compiler defines work. This
idea tries
     to resolve the problem in (1) with long unit names and with least amount of
     resistance to existing code. A namespace can be applied
     to a single unit, or to a group of units (think of it as a
"package"). To get this to
     work, we will have to introduce a new keyword and a new compiler parameter.
     Here follows examples of both.

     // per unit
    unit utils namespace companyxyz;
    uses
      ...
    end.

     ... or applied at compile time to all units being compiled.

     // our sample unit - as normal, nothing new
     unit utils;
     uses
       ...
     end.

     $ fpc -namespace=companyxyz utils.pas constants.pas ...

     ... if a conflict occurs, then you reference the unit with the
full namespace.
     eg:

       uses
          companyxyz.utils;  // because unit names must be valid
identifier and thus,
                                       // can't contain dots, when the
compiler sees this, it knows
                                       // companyxyz. is a namespace reference.
(...)

3)  Automatically add the directory where the unit is located, as the
namespace. Similar to what Java does.


Regarding your ideas 2 and 3: as they are not Delphi compatible they might be considered a "bad thing" (TM) by the FPC developers.

The problems of all three (or maybe all namespace ideas) is that they aren't compatible to older versions of Delphi (and FPC). Even if your second idea including compiler version checks is used, you'd be back at the start, because now you'd have a conflicting unit name.

Example:
I'll take the strutils example from rxlib:

unit strutils {$ifdef ver2_6_0}namespace rx{$endif};
(...)

So now we use a 2.4.0 compiler or a Delphi compiler and have a problem: How can I use the strutils from FPC/Delphi from a unit that uses strutils from rxlib?

The only solution to this might be

{$ifdef ver2_6_0}
unit strutils namespace rx;
{$else}
unit rxstrutils;
{$endif}

But now it gets ugly regarding uses-Clauses in rxlib itself and units that use rxlib. :(

Regarding your idea 3:

As FPC can use different directories for the search paths how would you solve similar hierarchies? Or a different problem: the source units of FCL packages reside in packages/$PackageName/src/ while the compiled units are in units/$Target/$PackageName/. What namespace should apply here? Where is the base of the namespace? Is it the FPC base dir? What about units that aren't part of FPC, like fpGUI?

Your idea 3 might become the most complicated one, because of the search path features that FPC has in comparison to Java.


If I'd have to choose one of your three ideas I'd choose the second one although it has some backwards-compatibility problems. But there still might be better ideas out there. :)

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to