[Gambas-user] Idea for 3.17

Brian G brian at westwoodsvcs.com
Wed May 5 17:00:40 CEST 2021


Reading this:
https://lists.gambas-basic.org/pipermail/user/2018-November/065829.html

It looks like what your trying to achieve is the possibility of having the same class definition or perhaps module(as they are kind of like a static class too) exportable from a component or library and being differentiated at compile/Run time by a namespace name. 

There are other uses I guess as in dynamic name spaces created inside a class or module(like c++). But I am not sure you are talking about that type of name space.

What I think you are talking about is if componentX exports circle and componentY exports circle there is no conflict in the symbol table or ability to reference both.

So why not simply and have a project parameter that specifies a separate namespace using the name of the project as the name space name. All references inside this container of course defaults to this name space. This would be most prevalent for components and libraries. Maybe a check box under the 'Project is translatable' checkbox, saying 'Project uses separate namespace' when creating the project. 

Does it require a separate symbol table at compile/link time or just that everything inside this project becomes qualified with the project name... lol 'myproject.myclass' actually in the symbol table for this project. It simplifies the integration of non qualified symbols.

In this way all references to anything in the project be in the form componentName.class, or componentname.module.mysub(). In fact the project name become the namespace name.

Maybe add a new 'with component1,component2 ... end with' to simplify search hierarchy for name resolution in app code. Removing the need in this section of code to keep adding the namespace.

Sort of like the java packages/c++ scope.

So in the project options page there would be a new checkbox to force a separate namespace for this component, library. Or just in general the application.

I guess really the container itself becomes a class of classes.

Things like export etc really don't need to be changed the language structure does not change much.

I guess a class load would be like Myclass = class.load("componentX.TheClass")

AS right now it looks like the first in is the one that is used. If component1 exports circle and component2 exports circle. And the current project has a circle class. Which ever class is loaded first is the one used throughout.. the application.

On Second thought.....

A More Integrated way:

I guess the classes collection would have to be extended with the component name as part of the class name to uniquely identify the name of each loaded class as well. The Class class already contains the component it belongs to.

Allow the component/library name once loaded to be used to qualify the class load references and in the default case work as it does today. Requires no changes to anything except how the compiler or runtime  sees the class/component name combination.
 
Having something like  component:classname as an extension to qualify the class to load we would not need anything new at all for name spaces except that syntax change and extending the way the compiler/runtime sees the name of classes to be loaded. This extension allows the loading of specific versions of the class. The container becoming the namespace. And always present.

** By container I mean project that being component , library, app

I guess the classes collection would have to be extended with the component name as part of the class name to uniquely identify the name of each loaded class as well. The Class class already contains the component it belongs to.

code sort of looks like

 dim a as new MyComponent:TheClass

 internally using same context

Anyway my two cents. Name spaces in the context of the project in simplifying class naming is a great idea. 
Probably lots of holes and a little naive, The second suggestion being my favorite.

"Failure is the key to success; 
 each mistake teaches us something"  .. Morihei Ueshiba
Brian G

----- On May 5, 2021, at 1:52 AM, Christof Thalhofer chrisml at deganius.de wrote:

> Hi,
> 
> what if we could work on namespaces? We already talked about it:
> 
> https://lists.gambas-basic.org/pipermail/user/2018-November/065829.html
> 
> Alles Gute
> 
> Christof Thalhofer
> 
> --
> Dies ist keine Signatur
> 
> 
> 
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----


More information about the User mailing list