Classes in PureBasic

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Classes in PureBasic

Post by BorisTheOld »

skywalk wrote:Hi Boris,
I agree with you, but your postings do nothing to affirm your "classy" statements.
They might as well be written in another language if they don't compile. :?:
Obviously, my sample class does compile, but only as part of a greater class and with the benefit of 114 macros that hide the clutter of PB's syntax.

The point of the exercise was to show the general structure of a class and to show that classes can be implemented. The point was not to show how to do it, since anyone who knows what a class is can put together the elements in a couple of days. And those who don't know what a class is should do some reading first. After which, they too could put together the elements in a couple of days.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Classes in PureBasic

Post by skywalk »

No disrespect intended as I did say I agree with your statements.
But, it would be helpful if you prefix such code posts with "non-working snippet".
Best not to assume the experience level of your audience. :wink:
I've written several thousand lines of code that "writes" code.
But, posting the preprocessed syntax would be meaningless without the preprocessor itself.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Classes in PureBasic

Post by BorisTheOld »

skywalk wrote:But, posting the preprocessed syntax would be meaningless without the preprocessor itself.
The example that I posted was real PB code, ready to be compiled -- no preprocessing required. It demonstrates how PB can be used to create structured, readable, OOP code.

Implementation is left as an exercise for the reader. :D
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
User avatar
Guevara-chan
User
User
Posts: 13
Joined: Sat Jun 18, 2011 12:20 pm

Re: Classes in PureBasic

Post by Guevara-chan »

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
Hm, already forgot reason why '_' was mercylessely kicked by dev team (inculding you) from role of line continuator ? No way:

Code: Select all

Module _ ; Show me any rule to not do it ?
External __.a ; Show me any rule to not do it ? x2
EndModule
Module __ ; Show me any rule to not do it ? x3
External _.a ; Show me any rule to not do it ? x4
EndModule
Debug ____ ; Where is thine God now ?
life MOV.I #life+1, *life
האם יש זמן לעצור ?
User avatar
X0r
Enthusiast
Enthusiast
Posts: 138
Joined: Tue May 01, 2007 3:49 am
Location: Germany

Re: Classes in PureBasic

Post by X0r »

Interesting discussion. Here is an old pseudo code I posted in the German forums a few years ago illustrating a possible use of modules in PB:

Code: Select all

Module Engine

  Public Procedure Start(...)
  
  EndProcedure

  Public Module Terrain
  
    Public Procedure Create(...)
    
    EndProcedure
  
  EndModule

EndModule



ImportModule Engine

Engine.Start(...)

Engine.Terrain.Create(...)
I think that using _ for the scope is just irritating as it may look the function like a globally defined one, just with a prefix added. So this would be just a kind of "semantic" implementation but I think we need a proper syntax for the modules in order to be able to distinguish between a module function call and a normal function call.
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Classes in PureBasic

Post by BorisTheOld »

Forge wrote:I think that using _ for the scope is just irritating as it may look the function like a globally defined one.......
I agree.

We use "_" in constant names, so if PB uses "_" in namespace references there is always the risk of name conflicts.

FreeBasic implements namespaces in a way that is very similar to the "With" statement, and uses the "." notation for referencing data and procedures. There is a description in the FreeBasic user manual.

A FreeBasic namespace does not represent a "black box" like a class or DLL, but is strictly a method of grouping related data and procedures without the need to prefix the names with a unique identifier. All data and procedures not in a namespace are assumed to be in an unnamed global namespace.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Classes in PureBasic

Post by User_Russian »

Do you plan to appearance of modules in nearest versions of PureBasic?
Fred
Administrator
Administrator
Posts: 16623
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Classes in PureBasic

Post by Fred »

Yes
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Classes in PureBasic

Post by skywalk »

Great news!
Will modules be supported without the use of projects?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred
Administrator
Administrator
Posts: 16623
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Classes in PureBasic

Post by Fred »

Sure.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Classes in PureBasic

Post by c4s »

:shock: That's going to be another awesome release! 8)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Classes in PureBasic

Post by Little John »

Fred, you are making me very curious. That's unfair. ;-)
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: Classes in PureBasic

Post by uwekel »

Fred wrote:Yes
Cool! :D
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
marroh
User
User
Posts: 72
Joined: Wed Aug 06, 2008 8:21 am

Re: Classes in PureBasic

Post by marroh »

User_Russian wrote:Do you plan to appearance of modules in nearest versions of PureBasic?
Fred wrote:Yes
Great news! A big thumbs up. :mrgreen:
PureBASIC v5.41 LTS , Windows v8.1 x64
Forget UNICODE - Keep it BASIC !
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Classes in PureBasic

Post by ts-soft »

:D great news :wink:
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.
Image
Post Reply