It is currently Wed Jun 19, 2013 4:26 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: Modules
PostPosted: Mon Aug 08, 2005 1:16 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 16, 2003 3:47 pm
Posts: 1285
Location: England
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:

Code:
global X
x = 5

UseModule(My_Module)
x = 7

debug x

UseModule()

debug x


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:

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


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:

Code:
ExcludeModule(Introduced_In_3.90)
IncludeModule(Removed_In_3.90)


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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 5:41 pm 
Offline
Moderator
Moderator

Joined: Sat Dec 27, 2003 3:55 am
Posts: 3332
Location: Great Southern Land
It took me a while to read through that and (partially) understand the advantages.

But this sounds pretty good! I wonder how difficult it would be to implement?

_________________
@}--`--,-- A rose by any other name ..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 11:50 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 5:05 pm
Posts: 1693
Location: Norway
You can do the same now, using structures!

Just use a index (array or list) of banks (structures) that contain all the data, pointers, etc.

This way you could simply specify a different index id, and you could read or write in a different bank (or memory bank as I guess you could also call it).

_________________
Image website, journal, projects, reviews and more.
Normality exist in the minds of others, not mine! - Rescator


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 1:50 am 
Offline
Addict
Addict
User avatar

Joined: Mon Sep 20, 2004 3:52 pm
Posts: 1651
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)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 8:25 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Apr 26, 2003 12:40 am
Posts: 738
Quote:
When programming projects get to a certain size PureBasic starts to struggle.


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!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 12:14 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 8951
Location: France
This module concept sound good for bigger projects, and we will think how to implement it cleanly.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 1:28 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 16, 2003 3:47 pm
Posts: 1285
Location: England
Thanks Fred.

I'm sure you'll be able to come up with something much cleaner than my efforts :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 4:03 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Dec 20, 2003 6:19 pm
Posts: 467
Location: Switzerland
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

_________________
Athlon64 3700+, 1024MB Ram, Radeon X1600


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 4:33 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Apr 26, 2003 12:40 am
Posts: 738
Successor to Modula. Both a language and an OS. Pretty good in fact. For those who like niche OS's


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 9:08 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 16, 2003 3:47 pm
Posts: 1285
Location: England
I was taught modula 5 at Uni.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 5:00 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Dec 20, 2003 6:19 pm
Posts: 467
Location: Switzerland
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:
Code:
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

EndModule

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
Code:
IncludeModule "one"  ; would import everything declared in the module as public

and optionally
Code:
IncludeModule "one"
  MyFunc.s(a.l, b.l) ; don't include myvar.q
EndIncludeModule



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:

_________________
Athlon64 3700+, 1024MB Ram, Radeon X1600


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 24, 2007 8:00 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Feb 16, 2006 1:41 am
Posts: 167
Location: New Zealand
Fred said:


Quote:
This module concept sound good for bigger projects, and we will think how to implement it cleanly


Hi Fred,

Any more on this, please?

_________________
WinXP Pro-SP3, PB4, slow CPU, ancient video card, fuzzy monitor
"When the facts change, I change my mind" - John Maynard Keynes


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 3:54 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 5:05 pm
Posts: 1693
Location: Norway
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)

_________________
Image website, journal, projects, reviews and more.
Normality exist in the minds of others, not mine! - Rescator


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 05, 2008 4:50 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 4:41 am
Posts: 320
Location: Canada
Fred wrote:
This module concept sound good for bigger projects, and we will think how to implement it cleanly.

PB in the tracks of Modula and ADA ? Wow. That will be great indeed.
Can we have it tomorrow? (just joking... Sunday will be fine.)

GedB wrote:
Thanks Fred.
I'm sure you'll be able to come up with something much cleaner than my efforts :)
Don't sell yourself short. You've presented a very clear case for a great improvement to our already excellent PB.

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.

_________________
"That's not a bug..." said the programmer. "...It's a feature! "
"Oh! I see..." replied the blind man.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 05, 2008 9:11 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat May 17, 2003 11:31 am
Posts: 5812
Module sounds pretty much to me like workspaces... or am I missing the point here?

_________________
( PB5.11 Win7 x64 Dell XPS710 Raid 0 VelociRaptor Intel Q6600 nForce 5 NVidia GTS450 )
( You have two options: psychotherapy, or the PureBasic Survival Guide... )


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye