It is currently Wed Aug 21, 2019 3:55 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 157 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 11  Next
Author Message
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 7:10 am 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3014
Location: Boston, MA
We go round and round...:mrgreen:
I vote for procedures in structures 8)
Then they are insulated and private until the structure is used.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 7:37 am 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1459
Location: North by Northwest
People emphasize too much on classes and forget that classes come at a cost, especially if you mix stuff like multiple inheritance into the mix.
There are other ways to get modular programming going. (without the complexity...)

@Fred
Maybe we can get this instead:
(similar to the Go language - it has no "classy" oop either)

Code:
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()))

Where the "(x.Foo)" is the receiver of the procedure.

In the long run this is much more flexible and maybe even more powerful than the "class" thing.
Especially if each include file is a module and therefore each module can have procedures with the same name.

_________________

I am to provide the public with beneficial shocks.
Alfred Hitshock


Last edited by fsw on Mon Feb 04, 2013 7:57 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 7:48 am 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1049
Location: Russia
Fred wrote:
PureBasic won't be object oriented, period.
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?
This can be a Name Space and (or) procedures within the structure.

Quote:
Especially if each include file is a module and therefore each module can have procedures with the same name.
+1000000

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 12:11 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13611
Location: France
Namespaces (modules) are planned for code isolation, but it won't be OOP.


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 12:58 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2923
Location: Planet Earth
Fred wrote:
Namespaces (modules) are planned for code isolation, but it won't be OOP.

How is it planned?

Code:
Module GUI
   Procedure OpenWindow(..)
   EndProcedure
EndModule

GUI\OpenWindow(...)
GUI->OpenWindow(...)
GUI_OpenWindow(...)
GUI#OpenWindow(...)
GUI?OpenWindow(...)
GUI::OpenWindow(...)

:?:


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 1:24 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13611
Location: France
Like that:

GUI_OpenWindow(...)

With an OpenModule/CloseModule to avoid the prefix if you want to.


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 1:30 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2923
Location: Planet Earth
Fred wrote:
Like that:

GUI_OpenWindow(...)

With an OpenModule/CloseModule to avoid the prefix if you want to.

Like this?
Code:
Module GUI
   Procedure OpenWindow(..)
   EndProcedure
EndModule

GUI_OpenWindow(...)

OpenModule GUI

    OpenWindow(...)

CloseModule

Sounds OK, but how is OpenWindow() within OpenModule/CloseModule differentiated from the real PB OpenWindow()? (name collision)


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 2:06 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13611
Location: France
It will raise an error if your command name clash (like an user lib), so you will have to use the module prefix.


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 2:11 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3694
Location: Italy
Code:
GUI_OpenWindow()


How do you know looking at the call you are invoking OpenWindow() in the module GUI and not a procedure named GUI_OpenWindow() ? After all GUI_OpenWindow is a valid name.

Wouldn't be better to use as separator something currently invalid in a procedure name ? For example GUI::OpenWindow()

Code:
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




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.


Shouldn't be the purpose of modules to avoid the name clashing in the first place ?

Shouldn't work the other way around then ?

If I use OpenModule all the procedures I call should be searched in that module first without any collision. If it's defined, I call that one.

If a procedure I call is not defined in the module, then the compiler should look outside the module, that way it would find the usual PB commands.

In case I know I want to call a procedure outside the module that has the same name of one in the module, I should have to specify the target module name in the call or the default "implicit" one using only the special chars "::".

Am I missing something ?

_________________
[ My little PureBasic review ]


Last edited by luis on Mon Feb 04, 2013 3:00 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 2:15 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1049
Location: Russia
Maybe better to do so?
Code:
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
Should support nested calls modules.
Code:
Module GUI

   Procedure OpenWindow(..)
   EndProcedure

EndModule
   
Module Event

   Procedure EventWindow(..)
   EndProcedure

EndModule


OpenModule GUI
 
  OpenWindow(..)

  OpenModule Event

     EventWindow(..)

  CloseModule ; Close Event (default)

CloseModule
Code:
OpenModule GUI
 
  OpenWindow(..)

  OpenModule Event

     EventWindow(..)

  CloseModule GUI

CloseModule Event

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 2:59 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2923
Location: Planet Earth
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.

Thanks!

Sounds OK, except that "Using Module Danilo" or just "Using Danilo" would be easier to use for end users (that use my inckude)
than "OpenModule Danilo" / "CloseMdule" combination.
Code:
Module Danilo
   Procedure New_Window(..)
   EndProcedure
EndModule

win1 = Danilo_New_Window(...)

OpenModule Danilo

    win2 = New_Window(...)

CloseModule


Code:
Module Danilo
   Procedure New_Window(..)
   EndProcedure
EndModule

win1 = Danilo_New_Window(...)


Using Module Danilo
; Using Danilo ; alternatively

win2 = New_Window(...)

Generally speaking it is just someting like With/EndWith?


Last edited by Danilo on Mon Feb 04, 2013 3:10 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 3:08 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3694
Location: Italy
Danilo wrote:
Sounds OK


Are you sure ? Don't you see a problem with that ?
viewtopic.php?p=403130#p403130

_________________
[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 3:09 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13611
Location: France
You don't have to close it, it's not mandatory. It can be useful to be able to unregister a module after use, so that's why it's here.


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 3:18 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2923
Location: Planet Earth
luis wrote:
Danilo wrote:
Sounds OK
Are you sure ? Don't you see a problem with that ?
viewtopic.php?p=403130#p403130

It's better than nothing! ;)
Code:
Module DirectX
   Procedure New_OpenScreen(..)
   EndProcedure
EndModule

Module OpenGL
   Procedure New_OpenScreen(..)
   EndProcedure
EndModule


OpenModule DirectX ; change to OpenGL to use another implementation

    scr = New_OpenScreen(...)

CloseModule

(Same could be done with changing 'XIncludeFile "DirectX.pbi"' to 'XIncludeFile "OpenGL.pbi"')


Top
 Profile  
Reply with quote  
 Post subject: Re: Classes in PureBasic
PostPosted: Mon Feb 04, 2013 3:24 pm 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5754
Location: Berlin - Germany
I miss a feature to protect a function in module. Protected functions only available inside the module block.

_________________
PureBasic 5.70 | SpiderBasic 2.21 | Windows 10 Pro (x64) | Linux Mint 19.2 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 157 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 11  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye