Declare External Variables &procedures for use w/in a module

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
jassing
Addict
Addict
Posts: 1768
Joined: Wed Feb 17, 2010 12:00 am

Declare External Variables &procedures for use w/in a module

Post by jassing »

Would be nice to have a way to declare a procedure as 'external' to the module; something like:

Code: Select all

global.l someVariable
DeclareModule test
  Declare.i MyFunc()
  DeclareExternal.s AnExternalFunc()
  ExternalVariable.l someVariable
EndDeclareModule
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Declare External Variables &procedures for use w/in a mo

Post by mk-soft »

I think this would not correspond to the philosophy for modules.
This would create dependencies to the main program.

In my opinion it is better in this case to work with common modules.

So from my side a
-1
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Declare External Variables &procedures for use w/in a mo

Post by #NULL »

mk-soft wrote:This would create dependencies to the main program.
If you have a dependency to some main scope or to some other module, it's a dependency either way. DeclareExternal is not a bad idea. IMO better would be a syntax to access the main scope (for all non-module symbols) and a PB:: scope for non-module PB-interal only. I think feature request in that direction exist.
Protecting the main scope from module symbols is a good idea. But completely protecting a module from any other non-module code (not even as optional explicit access) takes it away with the other hand.
jassing
Addict
Addict
Posts: 1768
Joined: Wed Feb 17, 2010 12:00 am

Re: Declare External Variables &procedures for use w/in a mo

Post by jassing »

mk-soft wrote:I think this would not correspond to the philosophy for modules.
This would create dependencies to the main program.
as already stated, it creates a dependency either way.
And since it's explicitly declared, it wouldn't impact the philosophy for modules by default, but rather enhance the concept of it.
I respect your opinion, but it shouldn't discount others.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Declare External Variables &procedures for use w/in a mo

Post by Little John »

#NULL wrote:IMO better would be a syntax to access the main scope (for all non-module symbols) and a PB:: scope for non-module PB-interal only. I think feature request in that direction exist.
My thoughts exactly.
See also viewtopic.php?p=529066#p529066
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Declare External Variables &procedures for use w/in a mo

Post by luis »

#NULL wrote: If you have a dependency to some main scope or to some other module, it's a dependency either way
I agree and I believe this magic aura around the concept of independence of modules is just an illusion.

I loosely quote myself:
The idea of the module as a black box, unless we are talking about trivial examples, it's a myth which cannot be attained.
Even using the officially supported common module mechanism the importing module would obviously depend on the common one.
The importing module must also know the name of the common module it wants to import, whilst by using "::" (the global scope resolution which we don't have) it doesn't need to know anything, it can just assume what it needs it's there in the global scope like any other PB command and use it by prepending a "::" to the symbol name.
Even when you use some OS APIs in your module you depend on them and if the OS version change or an API is not present anymore your module is broken because an external dependency is missing.
So instead of trying to enforce some philosophical and unreal view I would prefer to have something flexible to use in real life and to be able to choose what's best on a case by case basis.
Having the "::" to access the global scope does not mean you have to use it every time you write a module, it just means you don't have to make your life miserable writing long winded ugly code or using workarounds when the necessity arise. It's always better to have a choice.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
skywalk
Addict
Addict
Posts: 3994
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Declare External Variables &procedures for use w/in a mo

Post by skywalk »

I was eager for the module namespace but its implementation is not file based.
It places extra syntax burdens on the coder(many declares) that should/could have been automated by the compiler.
But, maybe not entirely if single pass?
For now, I use my own xxx_MyFunction(), yyy_MyFunction() namespaces and never have a problem.
Globals are always available and without "::" everywhere in my code.
And I never remember pointer, addressof, and prototype rules with "::"?
::*MyFunction() or *::MyFunction(), etc.
Last edited by skywalk on Sun Nov 18, 2018 6:06 pm, edited 1 time in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Declare External Variables &procedures for use w/in a mo

Post by Little John »

Luis, you are exaggerating a bit. :-)
The idea of the module as a black box, unless we are talking about trivial examples, it's a myth which cannot be attained.
Well, it might depend on your definition of "trivial". :-)
Personally, I do not consider e.g. this module viewtopic.php?f=12&t=45787
or this one viewtopic.php?p=524997#p524997 trivial.
In the meantime, many people have provided modules here that demonstrate how useful modules can be.
Even when you use some OS APIs in your module you depend on them and if the OS version change or an API is not present anymore your module is broken because an external dependency is missing.
:-)
And when the power supply of your computer is broken, you also can't use your modules anymore ... Of course nothing in the world is completely independent from everything else -- and nobody said that.
So instead of trying to enforce some philosophical and unreal view I would prefer to have something flexible to use in real life and to be able to choose what's best on a case by case basis.
As you probably know, I would like to have the same module improvements as you. However, modules as they are currently provided by PureBasic, are already of great practical use. I don't want to miss them anymore. Your repeated general "module bashing" is not helpful.
Post Reply