[Gambas-user] Proposal for namespace support

Christof Thalhofer chrisml at deganius.de
Wed May 12 01:06:18 CEST 2021


Hi Benoît,

Am 11.05.21 um 23:30 schrieb Benoît Minisini:

> Here is the result of my thoughts about namespace support.

Thank you!

> 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
things like

ComCompanyDb:Orm
ComCompanyCrypt:Hash

> 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:

'NameSpace:MyModule.MyMethod()'

If this becomes too long, other languages provide aliases. For example PHP:

https://www.php.net/manual/en/language.namespaces.importing.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
that). :-)

Alles Gute

Christof Thalhofer

-- 
Dies ist keine Signatur

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210512/f521cd22/attachment.sig>


More information about the User mailing list