Modules

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Post by Blue »

blueznl wrote:Module sounds pretty much to me like workspaces... or am I missing the point here?
Good observation.
They appear quite similar in what they bring to a language.

But modules, as defined in Modula and ADA, have a narrower meaning and role than Namepaces, don't they?.
They affect only the user's work product (his/her files), whereas namespaces also encompass pre-compiled libraries and other non-user stuff.

In the end, though, from a practical point of view, I think they're quite similar in that they achieve the same goal: structuring workflow and simplifying management in large projects. And, IMO, even small ones benefit, too.

correction:
Oupsie... I was also using workspace instead of namespace.
Too bad my brain is disconnected from my eyes...
Last edited by Blue on Tue Jul 08, 2008 9:57 am, edited 1 time in total.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

blueznl wrote:Module sounds pretty much to me like workspaces... or am I missing the point here?
Workspaces? Do you mean namespaces?
Well, namespaces are quite different. They just put an invisible prefix
in front of every "global" identifier. They can be nested, so if you get
code from somebody else and it conflicts with your existing code, just
put it in another namespace.
If everything was in modules, the only name conflicts possible are those
within modules or with module names. But there is one difference that
I find quite important. With modules, you are able to define an interface.
That means that you can define what is visible when you import a
module (which procedures and variables).

And they fit quite nicely with the concept of being able to precompile
modules or not having to recompile the whole project. So a module is
like an userlib with sourcecode.


If you meant something else, sorry :P
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Post by Blue »

remi_meier wrote:[...]So a module is like an userlib with sourcecode.
Nicely put.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Quentmeier
New User
New User
Posts: 5
Joined: Wed Jul 28, 2004 10:37 am

Post by Quentmeier »

This would be really cool. Hopefully modules will be implemented. I like the simplicity of Pure Basic, but Modules or a little OOP would really be great.
Greetings Lars
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Post by luis »

+ 1 for some kind of module implementation.

That would made writing PB libraries (kinda of, full source) a lot cleaner.

Please :)
cbrescia
New User
New User
Posts: 7
Joined: Tue Jul 22, 2008 11:50 pm
Location: Montevideo

Gtk style

Post by cbrescia »

Another way of doing large projects more readable and manageable is using the Gtk+ and some other libraries approach, (without entering OOP which would be advisable) is something like...

ControlEventHandler(Window,Control,function) // which is a call

Function // implementation
EndFunction

Modules in Oberon are not just libraries, they are compiled as needed
and loaded into memory at runtime, this way of Modula style helps to isolate parts of code, and according Wirth to avoid errors.
So modules would be welcome

Regards,
jeslar360
User
User
Posts: 20
Joined: Thu Aug 28, 2008 6:24 am

Post by jeslar360 »

I don't know if anyone here is familiar with an online game/environment called SecondLife, but this kind of reminds me of the use of States in LSL Script (Linden Scripting Language/secondLife Scripting Language).

Each state had its own events, There is the default "State" proclaimed as default, Example...


Code: Select all

integer complete = FALSE;

default
{
  state_enter()
  {
    if (!complete)
    {
      state some_state;
    } else {
      llSay(0, "Now Returning to the Default State");
    }
  }

  state_exit()
  {
    llSay(0, "Now Leaving the Default State");
  }
}

state some_state
{
  state_enter()
  {
    llSay(0, "You have entered another state!");
    complete = TRUE;
    llSleep(0.1);
    state default;
  }
}
All timers, listeners and variables that are created in an event...are cleared. All that remains, or the initial global variables declared outside the states.

Switching to another state can save memory and resources, which are very strict there.

Sorry for outside code like this...was just an example ;)
smishra
User
User
Posts: 70
Joined: Tue Jun 06, 2006 3:39 pm
Location: Maryland US

Another volte for modules

Post by smishra »

Another vote for modules.

Modules would be very helpful. I have a couple of projects that just cry out for implementation using modules.

The way I implement modules currently is to name all procedures and variables in that module with a module specific prefix like

moduleName_Variable1

moduleName_Procedure1()

and so on. It seems to work but C style headers would probably be better.

Sanjay Mishra
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

I think the better solution is to write more modular code rather than provide modular solutions for bad code.

Most of my libraries only use a single global which is uniquely named Glob_LibName.Glob_LibName or *Glob_LibNameLL.Glob_LibNameLL if it is a structured list. All commands are LibName_FunctionName or Private_LN_FunctionName (abbreviated for private functions).

My code is already modular and is designed to be this way. What benefit would these functions have that can't already be accomplished with good coding conventions?

The only thing I would like to see would be namespaces but this is an OO concept and unsuitable for PB's procedural paradigm.

If you're using something like this:

Code: Select all

Global GadgetWidth
Global Flags
Global Dim ItemNames(1)
.. for your global variables or a ubiquitous use of Shared variables then you're going to have problems.

Global only what will be uniquely limited to your library and try to global only one variable. Use a structure if you need more.

Don't use shared variables in large projects and always use the Protected keyword to keep your code portable and free from conflicts with other people's libraries.

Having to rename your variables on a per-library basis because they aren't portable to begin with is a backwards approach to programming well.
smishra
User
User
Posts: 70
Joined: Tue Jun 06, 2006 3:39 pm
Location: Maryland US

Some examples

Post by smishra »

It would be good if there was an example that demonstrated this approach. Most of the code in samples that come with Pure Basic are single file programs. An example program that spanned multiple files and demonstrated good modular programming practices would be great!
JCV
Enthusiast
Enthusiast
Posts: 580
Joined: Fri Jun 30, 2006 4:30 pm
Location: Philippines

Post by JCV »

ImageImage

Have a look on one of my old projects. You can see I separated the interface. I uses between gui or console mode. Single global file, separated network modules and recv and send packet modules, translation module, fileparsers, etc. All different modules are just included in my main source. Its very neat and easy to locate which part to fix or locate. Just imagine if I combine all this files into a single source file. (15k+ lines) :shock:

[Registered PB User since 2006]
[PureBasic 6.20][SpiderBasic 2.2]
[RP4 x64][Win 11 x64][Ubuntu x64]
smishra
User
User
Posts: 70
Joined: Tue Jun 06, 2006 3:39 pm
Location: Maryland US

Dumb Question

Post by smishra »

Here is a dumb question.

In C, for a module I define variables and procedures in the main source code file. For the variables and procedure that I want to expose to other modules I create an include header file that has statements

extern int c;
int doSomething();

can I achieve the same effect in PureBasic by using a header file like

shared c.l
Procedure doSomething()
User avatar
X0r
Enthusiast
Enthusiast
Posts: 138
Joined: Tue May 01, 2007 3:49 am
Location: Germany

Re: Modules

Post by X0r »

More and more users are asking for that feature and still there is no progress...
I am also running some big projects and in the course of the time it is getting hard to manage the codes.
Amundo
Enthusiast
Enthusiast
Posts: 200
Joined: Thu Feb 16, 2006 1:41 am
Location: New Zealand

Re: Modules

Post by Amundo »

It's a new year, and another request for this feature.

Please, Fred & Co. obviously people are writing larger and larger projects with PB, this feature would be a real plus!!!!

thanks!
Win10, PB6.x, okayish CPU, onboard video card, fuzzy monitor (or is that my eyesight?)
"When the facts change, I change my mind" - John Maynard Keynes
User avatar
X0r
Enthusiast
Enthusiast
Posts: 138
Joined: Tue May 01, 2007 3:49 am
Location: Germany

Re: Modules

Post by X0r »

Please, Fred & Co. obviously people are writing larger and larger projects with PB, this feature would be a real plus!!!!
Yes, definitively.
In a couple of months I am hopefully going to sign a contract with a company offering a famous product and I would love to realize this job in PB. But my last project already showed me that with the course of the time the way one usually manages and structures his code in PureBasic is no solution for complex applications.

If Fred does not make any changes according to this I am quite sure that PB will always remain on its status "language for beginners" and will never reach a higher level which would be quite sad considering its current potential.

BTW, Fred: Your argument concerning the OOP issue does not sound very plausible to me, sorry. I think BlitzMax is a quite good example that a BASIC language featuring both OOP and PP would not lead to splitting up the whole community.
Please think about it, make PureBasic more attractive.
Post Reply