[Gambas-user] Proposal for namespace support
chrisml at deganius.de
Wed May 12 01:06:18 CEST 2021
Am 11.05.21 um 23:30 schrieb Benoît Minisini:
> Here is the result of my thoughts about namespace support.
> I tried to find the simpler and less disturbing solution for the
> interpreter code.
> 1) A new syntax for exporting classes.
> ' Class MyClass
> Export As NameSpace:PublicName
> will export the class MyClass in the global table as "NameSpace:PublicName"
Looks good for me if we see the CamelCase in the IDE. Here I think of
> The MyClass name is still available inside the code of the current project.
Is the class also available inside the project under its Namespace
entry? This would make it easier to test it with gb.test.
> Note that the old 'Export' keyword alone would be an equivalent of
> 'Export As MyClass'
If we could do as a shortcut:
' Class MyClass
Export As NameSpace:
and this were extended to 'NameSpace:MyClass', that would be fine. Here
I think about typos where one would name the class file 'MyClass', then
writes 'Export As NameSpace:MzCass'.
Another Point: Can we make an entry in the '.project' file
'namespace=MyNameSpace' and if it is filled every class in the project
is automatically exported with 'MyNameSpace'? Except classes that the
author explicitly exported with another namespace.
This would also prevent us from typos. Is that complicated?
> 2) A new syntax for class names.
> Dim A As NameSpace:PublicName
> will automatically get the class named 'NameSpace:PublicName class' in
> the global table by the export made in 1)
With static classes this happens analogously? So that we can write:
If this becomes too long, other languages provide aliases. For example PHP:
has the syntax
'use MyReallyVeryLongNamespace as MyLong;'
> Do you think that it fulfills the needs detailed in the previous thread
> about namespaces?
I have to think about it for a while, but right now I think yes and also
that it is very elegant (especially to use the global symbol table for
Dies ist keine Signatur
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 833 bytes
Desc: OpenPGP digital signature
More information about the User