Nested modules

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Nested modules

Post 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
User avatar
X0r
Enthusiast
Enthusiast
Posts: 138
Joined: Tue May 01, 2007 3:49 am
Location: Germany

Re: Nested modules

Post by X0r »

+1

Without being able to use nested modules, the module feature is far less interesting.
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Nested modules

Post 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
User avatar
X0r
Enthusiast
Enthusiast
Posts: 138
Joined: Tue May 01, 2007 3:49 am
Location: Germany

Re: Nested modules

Post 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...
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Nested modules

Post 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 :)
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Nested modules

Post 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
User avatar
X0r
Enthusiast
Enthusiast
Posts: 138
Joined: Tue May 01, 2007 3:49 am
Location: Germany

Re: Nested modules

Post 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.
User avatar
X0r
Enthusiast
Enthusiast
Posts: 138
Joined: Tue May 01, 2007 3:49 am
Location: Germany

Re: Nested modules

Post 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?
Post Reply