Modules
Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Modules
When programming projects get to a certain size PureBasic starts to struggle.
The biggest problem is all the global stuff. Especially Arrays and Linked Lists.
It would be great if there was modular support.
At the moment we have a Global Space. Inside that global space exist all of the procedures, arrays, linked lists, global variables and object cursors.
By object cursors I mean the current object being used for images, files, databases, libraries, etc.
It would be great if the global space could be replaced with a module space. All of these global objects would then be contained within a module space.
There would be a default module, which everything would be contained in by default. This would mean that existing code would work without alteration inside the default module.
If a user calls 'UseModule(module_name) then control would switch to that module. UseModule() without a name would return control to the default modele.
For example, the following code would debug 7 followed by 5:
I'm sure the benefits of this would be obvious to anybody who has tried to write a library.
A command should exist for renaming modules, with settings available in the IDE. This will help to work around any name clashes that might occur.
So, for example, if both Joe and Bob have a My_HashTable Module and you want to use both the code can do this:
It should also be possible to Include and exclude modules into the default space.
For example IncludeModule(Joes_HashTable) would merge both the current module and the default space. ExcludeModule(Joes_HashTable) would then remove it. Then you could do this:
An optional 'Prefix' paramater would also be useful so that if Joes_Hashtable included the linked lists AllHashes() then a call to IncludeModule(Joes_HashTable, "Joes_" would make the procedure Joes_AllHashes() available in the default space.
Taking it further, module spaces could be created for older versions of the purelibraries. For example, all the hassles brought with the memory changes to memory could have been avoided. UseModule(Default_3.81) would return behaviour for AllocateMemory and the rest to the pre-3.90 style. Old code could be wrapped just have to be wrapped in these to ensure legacy support.
Even better, their could be module like 'Removed_In_3.90' and 'Introduced_In_3.90'. The latter would be automatically included in the default namespace.
The the following code would effectively roll back the compiler to before the change:
There could be an agreemeent that such transitional modules will remain for 12 months and then be removed. This would give those with a large body of purebasic code to support plenty of time to adapt, and these features would give them so many options on how best to handle the transition.
The biggest problem is all the global stuff. Especially Arrays and Linked Lists.
It would be great if there was modular support.
At the moment we have a Global Space. Inside that global space exist all of the procedures, arrays, linked lists, global variables and object cursors.
By object cursors I mean the current object being used for images, files, databases, libraries, etc.
It would be great if the global space could be replaced with a module space. All of these global objects would then be contained within a module space.
There would be a default module, which everything would be contained in by default. This would mean that existing code would work without alteration inside the default module.
If a user calls 'UseModule(module_name) then control would switch to that module. UseModule() without a name would return control to the default modele.
For example, the following code would debug 7 followed by 5:
Code: Select all
global X
x = 5
UseModule(My_Module)
x = 7
debug x
UseModule()
debug x
A command should exist for renaming modules, with settings available in the IDE. This will help to work around any name clashes that might occur.
So, for example, if both Joe and Bob have a My_HashTable Module and you want to use both the code can do this:
Code: Select all
IncludeFile(Bobs.pb)
IncludeFile(UsesBobs.pb)
IncludeFile(AlsoUsesBobs.pb)
RenameModule(My_HashTable, Bobs_HashTable)
; Everything up to this that referred to the My_HashTable is now mapped to Bobs_HashTable instead.
IncludeFile(Joes.pb)
IncludeFile(UsesJoes.pb)
IncludeFile(AlsoUsesJoes.pb)
RenameModule(My_HashTable, Bobs_HashTable)
; Everything up to this that referred to the My_HashTable is now mapped to Joes_HashTable instead.
UseModule(Bobs_HashTable)
; Work with Bobs library
UseModule(Joes_HashTable)
; Work with Joes library
Back to my library.
For example IncludeModule(Joes_HashTable) would merge both the current module and the default space. ExcludeModule(Joes_HashTable) would then remove it. Then you could do this:
An optional 'Prefix' paramater would also be useful so that if Joes_Hashtable included the linked lists AllHashes() then a call to IncludeModule(Joes_HashTable, "Joes_" would make the procedure Joes_AllHashes() available in the default space.
Taking it further, module spaces could be created for older versions of the purelibraries. For example, all the hassles brought with the memory changes to memory could have been avoided. UseModule(Default_3.81) would return behaviour for AllocateMemory and the rest to the pre-3.90 style. Old code could be wrapped just have to be wrapped in these to ensure legacy support.
Even better, their could be module like 'Removed_In_3.90' and 'Introduced_In_3.90'. The latter would be automatically included in the default namespace.
The the following code would effectively roll back the compiler to before the change:
Code: Select all
ExcludeModule(Introduced_In_3.90)
IncludeModule(Removed_In_3.90)
- dracflamloc
- Addict
Addict - Posts: 1648
- Joined: Mon Sep 20, 2004 3:52 pm
- Contact:
Post by dracflamloc »
I really think that there is a major need for non-global arrays.... I wish fred would implement this sometime soon.
(I know you could make a structure with an array inside it, and then declare multiple of those structures)
(I know you could make a structure with an array inside it, and then declare multiple of those structures)
Agree 100% - moaned about this some time ago. I have only recently been considering returning to a large-ish PB project simply because of the improved debugger (well done Fred and crew!). Still that leaves me with the problem of how to restructure my code to make it more manageable and modules would be great for this. It would also be absolutely fandozy (techy term) if modules supported seperate string spaces so we could multi-thread without problems. Bring it on!When programming projects get to a certain size PureBasic starts to struggle.
- remi_meier
- Enthusiast
Enthusiast - Posts: 468
- Joined: Sat Dec 20, 2003 6:19 pm
- Location: Switzerland
Post by remi_meier »
Just take a look at OBERON. It's a programming language based on
modules! I think Niklaus Wirth implemented it in a very good way!
(this way, it would also include a kind of OOP)
I think it was this site (http://oberon.ethz.ch/), but it doesn't load for
me at the moment...
But GedB's idea would also be enough for me.
greetz
Remi
modules! I think Niklaus Wirth implemented it in a very good way!
(this way, it would also include a kind of OOP)
I think it was this site (http://oberon.ethz.ch/), but it doesn't load for
me at the moment...
But GedB's idea would also be enough for me.
greetz
Remi
Athlon64 3700+, 1024MB Ram, Radeon X1600
- remi_meier
- Enthusiast
Enthusiast - Posts: 468
- Joined: Sat Dec 20, 2003 6:19 pm
- Location: Switzerland
Post by remi_meier »
Is there a chance for us to see this within this year?
It would be really cool if we could
- create modules
- define which procedures should be public (cleanly define the interface)
- perhaps with public variables, too
- separate compilation of each module (probably to .OBJ files)
- include them like normal include-files and optionally also define, which
procedures shall be included (smaller executable)
My syntax suggestion:
One could also use the ProcedureDLL approach, but it's not a DLL :D and
a cleanly defined interface separated from the code is much more readable
and IMO cleaner.
And include it like
and optionally
A module could also be compiled to a .OBJ file for use in other languages.
IMO it would be the best feature ever implemented since ~3 years :wink:
It would be really cool if we could
- create modules
- define which procedures should be public (cleanly define the interface)
- perhaps with public variables, too
- separate compilation of each module (probably to .OBJ files)
- include them like normal include-files and optionally also define, which
procedures shall be included (smaller executable)
My syntax suggestion:
Code: Select all
Module "one"
Export
MyFunc.s(a.l, b.l)
myvar.q
EndExport
Global myvar.q = 7
Procedure.s myintern()
ProcedureReturn "yeah!"
EndProcedure
Procedure.s MyFunc(a.l, b.l)
ProcedureReturn myintern()
EndProcedure
EndModulea cleanly defined interface separated from the code is much more readable
and IMO cleaner.
And include it like
Code: Select all
IncludeModule "one" ; would import everything declared in the module as publicCode: Select all
IncludeModule "one"
MyFunc.s(a.l, b.l) ; don't include myvar.q
EndIncludeModuleA module could also be compiled to a .OBJ file for use in other languages.
IMO it would be the best feature ever implemented since ~3 years :wink:
Athlon64 3700+, 1024MB Ram, Radeon X1600
Might be better to merge this module idea with project libs instead.
PB compiling code or a set of includes into PB libs of some sort.
AmigaE had modules like this, not sure about how memory and stuff like that was used though, but the semi compiled (can't recall exactly what they where, I hope Fred might recall though)
modules was very practical as they basically contained the code needed to call the code within that module. (again my memory is hazy whether a module included or just linked to other modules, I think it included though so a module that included 3 other modules would be bigger in size than mere linking would, this would also reduce issues of code changes in other modules, provided the referenced module is not recompiled)
PB compiling code or a set of includes into PB libs of some sort.
AmigaE had modules like this, not sure about how memory and stuff like that was used though, but the semi compiled (can't recall exactly what they where, I hope Fred might recall though)
modules was very practical as they basically contained the code needed to call the code within that module. (again my memory is hazy whether a module included or just linked to other modules, I think it included though so a module that included 3 other modules would be bigger in size than mere linking would, this would also reduce issues of code changes in other modules, provided the referenced module is not recompiled)
PB in the tracks of Modula and ADA ? Wow. That will be great indeed.Fred wrote:This module concept sound good for bigger projects, and we will think how to implement it cleanly.
Can we have it tomorrow? (just joking... Sunday will be fine.)
Don't sell yourself short. You've presented a very clear case for a great improvement to our already excellent PB.GedB wrote:Thanks Fred.
I'm sure you'll be able to come up with something much cleaner than my efforts :)
May I squeak a one penny suggestion along GedB's suggestions ?
Falling back into the default module should be a very clear explicit command.
GedB suggested UseModule();
I would say UseMain or UseDefault.
Same difference (as they say here), but clearer.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Module sounds pretty much to me like workspaces... or am I missing the point here?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Return to "Feature Requests and Wishlists"
Jump to
- PureBasic
- ↳ Coding Questions
- ↳ Game Programming
- ↳ 3D Programming
- ↳ Assembly and C Programming in PureBasic
- ↳ The PureBasic Editor
- ↳ The PureBasic Form Designer
- ↳ General Discussion
- ↳ Feature Requests and Wishlists
- ↳ Tricks 'n' Tips
- Bug Reports
- ↳ Bugs - Windows
- ↳ Bugs - Linux
- ↳ Bugs - Mac OSX
- ↳ Bugs - C backend
- ↳ Bugs - 3D Engine
- ↳ Bugs - IDE
- ↳ Bugs - Documentation
- OS Specific
- ↳ AmigaOS
- ↳ Linux
- ↳ Windows
- ↳ Mac OSX
- ↳ Raspberry PI
- Miscellaneous
- ↳ Announcement
- ↳ Off Topic
- Showcase
- ↳ Applications - Feedback and Discussion
- ↳ PureFORM & JaPBe
- ↳ TailBite