Classes in PureBasic
Re: Classes in PureBasic
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
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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
-
- Addict
- Posts: 1443
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Classes in PureBasic
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.
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.
So it is better not to waste time on the modules than to implement them according to your plan.
Imagine you have a game engine (for example), divided into several modules. Engine itself is a module, and modules engine - nested modules main module.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.
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.
For example, 3D function.freak wrote:What other feature should we have dropped to get the time for this?
Last edited by User_Russian on Mon Feb 04, 2013 9:18 pm, edited 1 time in total.
Re: Classes in PureBasic
Oh ... if you mean my quiping ... sorry if it was to much.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?
Re: Classes in PureBasic
Fred, the same stuff can be achieved with less complication, just look at the above post of mine.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: ...
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
Code: Select all
Crypto1\\Cipher() ; call Cipher from module 1
Crypto2\\Cipher() ; call Cipher from module 2
Thanks for reading
I am to provide the public with beneficial shocks.
Alfred Hitshock
Re: Classes in PureBasic
Thanks for the more detailed info. The "External" bit was the piece missing to make it work better for me.
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 ?
Scenario: you include the source of module MOD in your main program, the module contains a Foo() procedure inside it (scope defined below).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.
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 ?
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Classes in PureBasic
Yes, that would be simple and useful.fsw wrote:We have already IncludeFile and IncludeBinary why not add IncludeModule and make each file a module?
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
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
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
Windows 11, Manjaro, Raspberry Pi OS
Re: Classes in PureBasic
Be honest: The second one is the critical onets-soft wrote:[...] To make Binary modules around the code before others inaccessible,
around this to selling or simply because one is ashamed of that
The concept above would apply to all names. The procedures are just examples.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!
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:Imagine you have a game engine (for example), divided into several modules. Engine itself is a module, and modules engine - nested modules main module.
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?User_Russian wrote:freak wrote:
What other feature should we have dropped to get the time for this?
For example, 3D function.
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.PMV wrote:Oh ... if you mean my quiping ... sorry if it was to much.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?
You get an "already defined" error because you can see the one in the module and try to define something with the same name.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 ?)
quidquid Latine dictum sit altum videtur
Re: Classes in PureBasic
I think adding a Alias was a good idea
No conflict
Code: Select all
Module GUI
External Procedure Foo()
EndProcedure
EndModule
Procedure Foo()
EndProcedure
OpenModule GUI As Blub
BLub_Foo()
Foo()
CloseModule
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Re: Classes in PureBasic
No an underscore makes no sense.idle wrote:it makes perfect sense to use an underscore
At least to me
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
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
Using NameSpace/EndNameSpace, UseNameSpace/CloseNameSpace and other things are not clever, it asks for trouble...
This is my opinion and I stick to it
Last edited by fsw on Mon Feb 04, 2013 10:21 pm, edited 1 time in total.
I am to provide the public with beneficial shocks.
Alfred Hitshock
Re: Classes in PureBasic
By 'names' you mean constants and structures would be isolated too?freak wrote:The concept above would apply to all names. The procedures are just examples.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 nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Classes in PureBasic
Yes.skywalk wrote:By 'names' you mean constants and structures would be isolated too?freak wrote:The concept above would apply to all names. The procedures are just examples.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!
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
quidquid Latine dictum sit altum videtur
Re: Classes in PureBasic
Ok, that is very tempting and I will sacrifice my top wish for modules
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Classes in PureBasic
With that the underscore makes much more sense as everything else. But ifreak wrote:The concept above would apply to all names. The procedures are just examples.
will repeat myself ... It is a solid design and thats what i expected. Very nice!
Only still curious about the release version.
Re: Classes in PureBasic
See why we don't talk about next features publicly