Page 2 of 4

Posted: Sat Jul 05, 2008 7:59 pm
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...

Posted: Mon Jul 07, 2008 6:08 pm
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

Posted: Tue Jul 08, 2008 9:59 am
by Blue
remi_meier wrote:[...]So a module is like an userlib with sourcecode.
Nicely put.

Posted: Thu Aug 07, 2008 11:15 am
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

Posted: Thu Aug 28, 2008 5:10 pm
by luis
+ 1 for some kind of module implementation.

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

Please :)

Gtk style

Posted: Wed Sep 03, 2008 7:17 pm
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,

Posted: Thu Sep 04, 2008 6:48 am
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 ;)

Another volte for modules

Posted: Sun Nov 23, 2008 11:35 am
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

Posted: Sun Nov 23, 2008 5:56 pm
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.

Some examples

Posted: Sun Nov 23, 2008 8:37 pm
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!

Posted: Mon Nov 24, 2008 1:58 am
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:

Dumb Question

Posted: Mon Nov 24, 2008 2:32 am
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()

Re: Modules

Posted: Sun Jan 23, 2011 3:00 am
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.

Re: Modules

Posted: Wed Jan 26, 2011 11:42 pm
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!

Re: Modules

Posted: Fri Jan 28, 2011 1:43 am
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.