Page 1 of 1

Nested modules

Posted: Sat Jun 29, 2013 1:29 pm
by User_Russian
It would be great if one could use nested modules.

Code: Select all

DeclareModule x

EndDeclareModule


Module x

  DeclareModule y

  EndDeclareModule
  
  Module y
  
  EndModule
  
EndModule

Re: Nested modules

Posted: Thu Dec 10, 2015 8:52 pm
by X0r
+1

Without being able to use nested modules, the module feature is far less interesting.

Re: Nested modules

Posted: Fri Dec 11, 2015 12:45 am
by DontTalkToMe
Even without considering how modules have been implemented which make this highly unlikely, there is this statement

http://www.purebasic.fr/english/viewtop ... 25#p403225

Re: Nested modules

Posted: Sat Dec 12, 2015 3:56 am
by X0r
freak did not provide any evidence for some of his statements. For instance:
I don't know a real world project that uses nested namespaces [...]
There are a lot of libraries/frameworks making use of nested namespace. Think of the .NET framework for instance...

Re: Nested modules

Posted: Sat Dec 12, 2015 11:52 am
by DontTalkToMe
I agree with you, but unfortunately I don't think it's going to change anything.

Global scope resolution too is available in other languages supporting namespaces and even if requested at the time of modules introduction by some users, PB developers were opposed to it (just search the forum) and it has not been implemented.

Another thing very useful if we had nested modules in the first place would be aliases, to shorten a namespace specification.

Something like

Code: Select all

Draw Alias System::Graphic::Drawing
This would be useful even now, to reduce typing while keeping meaningful module names and it's something easier to implement compared to nested modules.

To people thinking about using a macro to shorten the name of the module. No thanks, clearly it's not the same.
For one, autocomplete just stops to work.

Good luck with the request, hope you'll get it :)

Re: Nested modules

Posted: Sat Dec 12, 2015 4:17 pm
by PMV
Nested modules would only make a difference for me, if the scope of the
inner modules is only inside the parent module, where they are defined.
Thats where i see nested modules necessary.

A module can only accessed by modules, that are defined in the same
parent module. Child modules will not inherit parent parent module
definition. That is, what i would like to have, just one level.
Strict isolation like that would help huge projects.

Of course, if modules would be usable as namespaces, too ...
i wouldn't blame anyone. :lol:
But the most important thing is the strict isolation of just one level.

MFG PMV

Code: Select all

DeclareModule MainModule
  Declare Test()
EndDeclareModule


Module MainModule
  DeclareModule Nested0Y
    Declare Test()
  EndDeclareModule
  
  DeclareModule Nested0X
    Declare Test()
  EndDeclareModule
  
  Module Nested0Y
    DeclareModule Nested1Y
      Declare Test()
    EndDeclareModule
    
    Module Nested1Y
      Procedure Test()
      EndProcedure
      
    EndModule
    
    Procedure Test()
      Nested1X::Test() ; disallowed
      Nested1Y::Test() ; allowed
    EndProcedure
  EndModule
  
  
  Module Nested0X
    DeclareModule Nested1X
      Declare Test()
    EndDeclareModule
    
    Module Nested0X
      Procedure Test()
      EndProcedure
    EndModule
    
    Procedure Test()
      Nested1X::Test() ; allowed
      Nested1Y::Test() ; disallowed
    EndProcedure
  EndModule
  
  
  
  Procedure Test()
    Nested0X::Test() ; allowed
    Nested0Y::Test() ; allowed
    
    Nested0X::Nested1X::Test() ; disallowed
    Nested0Y::Nested1Y::Test() ; disallowed
  EndProcedure
EndModule

MainModule::Test() ; allowed
MainModule::Nested0X::Test() ; disallowed
MainModule::Nested0Y::Test() ; disallowed
MainModule::Nested0X::Nested1X::Test() ; disallowed
MainModule::Nested0Y::Nested1Y::Test() ; disallowed

Re: Nested modules

Posted: Sun Dec 13, 2015 11:38 pm
by X0r
MainModule::Nested0X::Test() ; disallowed
I would not disallow this. Think of the .NET framework again. It is popular for its well designed structure and allows this type of constructs.
How about keywords like Private and Public for nested modules? By this way the programmer would be able to choose where a nested module is visible and where not.

Re: Nested modules

Posted: Tue May 12, 2020 12:03 am
by X0r
Having launched a new (larger) project in PureBasic, I am still missing nested modules. Is there any good reason as to why we are not getting this feature?