Am 24.06.2018 um 16:49 schrieb Marcos Douglas B. Santos:
Hypothetically, let's suppose that Windows and Graphics unit belongs
to `FPC.RTL.` namespace, a "long name".
Using a syntax sugar to macros, I propose to implement the "as"
keyword in units declarations:

=== code begin ===
uses
    FPC.RTL.Windows as Win,
    FPC.RTL.Graphics as Graph;
var
   B1: Win.TBitmap;
   B2: Graph.TBitmap;
=== code end ===

if I understood right, the compiler "just" need to replace this syntax
to use macros:

=== code begin ===
uses
    {$macro on}
    FPC.RTL.Windows,
    {$define Win := FPC.RTL.Windows}
    FPC.RTL.Graphics as Graph;
    {$define Graph := FPC.RTL.Graphics}
var
   B1: Win.TBitmap;
   B2: Graph.TBitmap;
=== code end ===

In my company we are used to use namespaces like
`Acme.SysFoo.Finances.Billing.Utils.Classes` (just an example).
Depending on the context, I could code `uses ... as Billing;`
Using `Billing` as prefix for all interfaces/classes that has the same
names in others units.
You can make use of default namespaces using -FN<x>.

For your first example you'd use -FNFPC.RTL and then you could simply put the units Windows and Graphics into the uses sections.

For your other example let it be said that with default namespaces you can use any part of the name to resolve ambiguities: E.g. with -FNAcme.SysFoo.Finances.Billing.Utils and a "uses Classes" (though I wouldn't recommend that one due to potential conflict with the RTL unit :P ) you could use any of the following to refer to the "Classes" unit:

Classes
Utils.Classes
Billing.Utils.Classes
Finances.Billing.Utils.Classes
SysFoo.Finances.Billing.Utils.Classes
Acme.SysFoo.Finances.Billing.Utils.Classes

Other than that I think the task of reducing typing for this is better put into the hands of the code completion of a capable IDE.

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

Reply via email to