Re: Classes in PureBasic
Posted: Sun Feb 03, 2013 11:15 pm
PureBasic won't be object oriented, period.
http://www.purebasic.com
https://www.purebasic.fr/english/
A language supporting OOP natively can boast a simpler and cleaner syntax then using interfaces and explicit virtual tables in PB ?Danilo wrote: Even C++ is simpler and cleaner.![]()
Hi Boris,BorisTheOld wrote:Dare I say, once again, that PB already has everything one needs to create classes.
We use classes for every aspect of our applications. It's easy to do and creates well structured code.
The future is already here.![]()
Here's an example. This class works with others to implement a menu structure in the form of a Tree gadget. It uses standard PB features and is cross-platform.
It is more interesting how many years we still haveFred wrote:PureBasic won't be object oriented, period.
Code: Select all
Module MyMod
Structure Foo
intFoo.i
EndStructure
Procedure.i (x.Foo) Get()
ProcedureReturn x\intFoo
EndProcedure
Procedure (x.Foo) Set(value.i)
x\intFoo = value
EndProcedure
;- main
Global myfoo.Foo
myfoo\Set(123)
PrintN(Str(myfoo\Get()))
Fred, let it be, not OOP, but need of isolation procedures (procedures available from a limited part of the code). Otherwise difficult to develop and support projects. I hope you agree with this?Fred wrote:PureBasic won't be object oriented, period.
+1000000Especially if each include file is a module and therefore each module can have procedures with the same name.
How is it planned?Fred wrote:Namespaces (modules) are planned for code isolation, but it won't be OOP.
Code: Select all
Module GUI
Procedure OpenWindow(..)
EndProcedure
EndModule
GUI\OpenWindow(...)
GUI->OpenWindow(...)
GUI_OpenWindow(...)
GUI#OpenWindow(...)
GUI?OpenWindow(...)
GUI::OpenWindow(...)
Like this?Fred wrote:Like that:
GUI_OpenWindow(...)
With an OpenModule/CloseModule to avoid the prefix if you want to.
Code: Select all
Module GUI
Procedure OpenWindow(..)
EndProcedure
EndModule
GUI_OpenWindow(...)
OpenModule GUI
OpenWindow(...)
CloseModule
Code: Select all
GUI_OpenWindow()
Code: Select all
Module GUI
Procedure OpenWindow(..)
EndProcedure
EndModule
GUI::OpenWindow(...) ; call the one defined in the module GUI
OpenModule GUI
OpenWindow(...) ; call the one defined in the module GUI
CloseModule
OpenModule GUI
Other::OpenWindow(...) ; call another OpenWindow from another module
::OpenWindow(...) ; call the implicit module (the only one we have now) hence call the PB OpenWindow
OpenWindow(...) ; call the one defined in the module GUI
OpenScreenWindow(...) ; not defined in the module, call the PB command
CloseModule
Shouldn't be the purpose of modules to avoid the name clashing in the first place ?Fred wrote:It will raise an error if your command name clash (like an user lib), so you will have to use the module prefix.
Code: Select all
Module GUI Extends Wind ; Inheritance module Wind.
Public ; Exported from the module.
Pos.POINT
Procedure OpenWindow(..)
EndProcedure
Private ; No exported from the module.
Structure MyStruct
x.l
EndStructure
Win.RECT
Procedure WindowParam(..)
EndProcedure
EndModule
x.MyStruct ; Error - Private Structure.
OpenModule GUI
Pos\x=0 ; OK.
OpenWindow(..) ; OK
Win\left = 4 ; Error - Private Structure
WindowParam(..) ; Error - Private Procedure.
x.MyStruct ; Error - Private Structure.
CloseModule
Code: Select all
Module GUI
Procedure OpenWindow(..)
EndProcedure
EndModule
Module Event
Procedure EventWindow(..)
EndProcedure
EndModule
OpenModule GUI
OpenWindow(..)
OpenModule Event
EventWindow(..)
CloseModule ; Close Event (default)
CloseModule
Code: Select all
OpenModule GUI
OpenWindow(..)
OpenModule Event
EventWindow(..)
CloseModule GUI
CloseModule Event
Thanks!Fred wrote:It will raise an error if your command name clash (like an user lib), so you will have to use the module prefix.
Code: Select all
Module Danilo
Procedure New_Window(..)
EndProcedure
EndModule
win1 = Danilo_New_Window(...)
OpenModule Danilo
win2 = New_Window(...)
CloseModule
Code: Select all
Module Danilo
Procedure New_Window(..)
EndProcedure
EndModule
win1 = Danilo_New_Window(...)
Using Module Danilo
; Using Danilo ; alternatively
win2 = New_Window(...)