Page 4 of 11

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 8:54 pm
by ts-soft
The Concept by Fred is good!

Only one wish: Source-Module and Binary-Module
To make Binary modules around the code before others inaccessible,
around this to selling or simply because one is ashamed of that :mrgreen:

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 9:07 pm
by User_Russian
freak, If we add modules in PB, it is necessary do it properly, rather than pseudo-modules, you have to offer. All constants, structures, procedures need to be isolated from the main program, and then the that suggest, can not be called isolation!
So it is better not to waste time on the modules than to implement them according to your plan. :( :(
freak wrote:Modules in modules:
I don't see a common need for this. I have a hard time coming up with a useful example for it to be honest. And the semantics of such a feature would be hard to define and understand. Once again: we are trying to keep things understandable and not make them unnecessarily complex.
Imagine you have a game engine (for example), divided into several modules. Engine itself is a module, and modules engine - nested modules main module.
Why do it?
For isolation of code. Using modules of the required functions are exported engine, but the program will not be available functions and structures of the inner engine modules.

But on your plan, it does not make sense, because there is no complete isolation of code.
freak wrote:What other feature should we have dropped to get the time for this?
For example, 3D function.

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 9:10 pm
by PMV
freak wrote:Its not like we did nothing all these years. Look at the release history. What other feature should we have dropped to get the time for this?
Oh ... if you mean my quiping ... sorry if it was to much. :)

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 9:13 pm
by fsw
Fred wrote:As you seem interested by the module topic, here is our draft, so you can get a better idea. Please keep in mind than it's no promise, we can drop it if we change our mind so don't expect it for the next version.

Code: Select all

      ; Here is my suggestion: ...

Fred, the same stuff can be achieved with less complication, just look at the above post of mine.

We have already IncludeFile and IncludeBinary why not add IncludeModule and make each file a module?
There is no need for Module/EndModule and stuff that over-complicates things.

In Go if there are several procedures with the same name (because several modules are imported) the only thing that needs to be done is:

Code: Select all

Crypto1.Cipher() ; call Cipher from module 1
Crypto2.Cipher() ; call Cipher from module 2
the PureBasic equivalent could look like this:

Code: Select all

Crypto1\\Cipher() ; call Cipher from module 1
Crypto2\\Cipher() ; call Cipher from module 2
Please keep it simple.

Thanks for reading :wink:

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 9:22 pm
by luis
Thanks for the more detailed info. The "External" bit was the piece missing to make it work better for me.
freak wrote:There is no confusion between an X_Foo() procedure that belongs to module X and another X_Foo() procedure that you write elsewhere because you can't. They refer to the same thing.
Scenario: you include the source of module MOD in your main program, the module contains a Foo() procedure inside it (scope defined below).

1) You don't use OpenModule

1A) Foo() in the module is private (default)
You try do define a Foo() proc in the main program. Should be possible.
You call that proc with Foo() and can't access the one inside the module. OK.

1B) Foo() in the module is External
You try do define a Foo() proc in the main program. Should be possible (?)
You call that proc with Foo() and the one inside the module with MOD_Foo(). OK.

2) You use OpenModule MOD

1A) Foo() in the module is private (default)
You try do define a Foo() proc in the main program. Should be possible.
You call that proc with Foo() and can't access the one inside the module. OK.

1B) Foo() in the module is External
You try do define a Foo() proc in the main program. What happens ? Error ? (you now can access Foo() in the module simply through its name right ?)

Is all the above right ?

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 9:34 pm
by Little John
fsw wrote:We have already IncludeFile and IncludeBinary why not add IncludeModule and make each file a module?
Yes, that would be simple and useful.
Each file included by "IncludeModule" is a separate namespace. But procedures, structures or variables in the module which are declared "External" can be also accessed by code which is outside of the module. Keep it really simple. :-)

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 9:47 pm
by idle
it makes perfect sense to use an underscore
So how would you escape a namespace and call a globally scoped function from within a namespace
seems like we need an escape symbol

Code: Select all

;globally scoped function
Procedure Foo() 
;...
EndProcedure 

NameSpace Foo 
   state.i
   procedure Foo() 
   ;...
   EndProcedure 
EndNameSpace

UseNameSpace Foo 
   Foo() 
   ;how to escape a namespace to the global namespace?         
   _foo() ; using underscore could break existing code 
   \foo() ; is just confusing    
   ::foo() ;would work well   
   
   ;or like like this which would be a hassle   
    UseNameSpace Main 
       foo() 
    CloseNameSpace 
 

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 9:48 pm
by freak
ts-soft wrote:[...] To make Binary modules around the code before others inaccessible,
around this to selling or simply because one is ashamed of that :mrgreen:
Be honest: The second one is the critical one :D
User_Russian wrote: All constants, structures, procedures need to be isolated from the main program, and then the that suggest, can not be called isolation!
The concept above would apply to all names. The procedures are just examples.
User_Russian wrote:Imagine you have a game engine (for example), divided into several modules. Engine itself is a module, and modules engine - nested modules main module.
You can have the nested modules side by side. Just use descriptive names and there will be no problem. There is no need for them to be nested. I don't know a real world project that uses nested namespaces, even though other languages allow it. People avoid this because it makes things more complex, not less.
User_Russian wrote:freak wrote:
What other feature should we have dropped to get the time for this?
For example, 3D function.
That is just your opinion. If i ask somebody else he would mention your most favorite feature. Would you be ok if we had postponed that?
PMV wrote:
freak wrote:Its not like we did nothing all these years. Look at the release history. What other feature should we have dropped to get the time for this?
Oh ... if you mean my quiping ... sorry if it was to much. :)
It was aimed at the general "why did feature X take so many years?" questions. Its not feature X that took so long. The tons of other features combined did.
luis wrote: 1B) Foo() in the module is External
You try do define a Foo() proc in the main program. What happens ? Error ? (you now can access Foo() in the module simply through its name right ?)
You get an "already defined" error because you can see the one in the module and try to define something with the same name.

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 10:11 pm
by ts-soft
I think adding a Alias was a good idea

Code: Select all

Module GUI
  External Procedure Foo()
  EndProcedure
EndModule

Procedure Foo()
EndProcedure

OpenModule GUI As Blub
  BLub_Foo()
  Foo()
CloseModule
No conflict

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 10:17 pm
by fsw
idle wrote:it makes perfect sense to use an underscore
No an underscore makes no sense.
At least to me :P

This is better:

Code: Select all

Module main
IncludeModule "myFoo" ; has a Foo() procedure

Procedure Foo() 
;...
EndProcedure 

   Foo() ; this is the local Foo
   myFoo\\Foo() ; this is the Foo from module myFoo
   
Besides "\" is used for structure items; it makes sense to use "\\" for module items.

If there is no local Foo() the code could look like this:

Code: Select all

Module main
IncludeModule "myFoo" ; has a Foo() procedure

   Foo() ; this is the Foo from module myFoo
   
No module name needed as there is only one Foo().


Using NameSpace/EndNameSpace, UseNameSpace/CloseNameSpace and other things are not clever, it asks for trouble...

This is my opinion and I stick to it :mrgreen:

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 10:21 pm
by skywalk
freak wrote:
User_Russian wrote: All constants, structures, procedures need to be isolated from the main program, and then the that suggest, can not be called isolation!
The concept above would apply to all names. The procedures are just examples.
By 'names' you mean constants and structures would be isolated too?

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 10:26 pm
by freak
skywalk wrote:
freak wrote:
User_Russian wrote: All constants, structures, procedures need to be isolated from the main program, and then the that suggest, can not be called isolation!
The concept above would apply to all names. The procedures are just examples.
By 'names' you mean constants and structures would be isolated too?
Yes.

Btw, another reason for the '_': #MyConstant inside Module Foo becomes "#Foo_MyConstant" which looks good. "Foo::#MyConstant" or "#Foo::MyConstant" are both a bit weird imho :)

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 10:49 pm
by skywalk
Ok, that is very tempting and I will sacrifice my top wish for modules :mrgreen:

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 11:00 pm
by PMV
freak wrote:The concept above would apply to all names. The procedures are just examples.
With that the underscore makes much more sense as everything else. But i
will repeat myself ... It is a solid design and thats what i expected. Very nice!
Image



Only still curious about the release version. :P

Re: Classes in PureBasic

Posted: Mon Feb 04, 2013 11:08 pm
by Fred
See why we don't talk about next features publicly ;)