Easy object oriented programming (just look at my example)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?

Was this a good idea?

Yes.
50
56%
No.
19
21%
Maybe.
20
22%
 
Total votes: 89

dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

I'm still on the fence on this one.... don't know either way.

I reckon that the current interfaces and the (near future) 4.0 prepocessor will go a long way to allow you to do what is done in C for years already: OO-like programming, without a fullblown OO language. Basically, this entails consolidating variables and (pointers to) code in structs, and using macro preprocessing to dereference pointers to the appropriate code/method. Scope rules (especially file scope rules) are used to prevent direct access to functions, everything needs to be handled through the pointer indirection embedded in the structs.
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

OOP is more of a technique than just available commands. Encapsulation ( an OO concept ) can be done in procedural as well, i.e. coding your functions to perform one unit-of-work, which facilitates reusability. Too often, even in OO-code, coders bloat their functions and make them too specific to be used in more than one place in the overall application. OO nor Procedural forces good coding techniques. This is why programming is an art not a science. :wink:

BTW, Drac posted an OO-in-PureBasic tutorial on PureArea.net that was not referenced in this thread, so here it is Drac's OO Tutorial. This has worked well for me.

I think with Didelphodon's pre-compiler (see page 4 of this thread), PureBasic is already OOP, however, it would be nice to see a native Class/EndClass structure that allows embedded functions. That would be the only thing necessary.

/voted yes
//does OOP for a living
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

And well, must we expect something of this in PB 4? :) The votations say yes.

I am playing with BlitzMax a little bit, but what i found?:
BlitzMax is a C++ with a modified syntax and some adds.
It's like a modified C++ :shock:
The first post i wrote in this thread suggests a not so imitating way to do things. The way used by BMX is shamefully complex. A complexity clonation of C++.
Mark Sibly didn't crushed his mind about making things easy and different of C++ when developed BMX :!:
Of course, there are ways to implement OOP in a language in a easy and pleasant way for the programmer :!:
Num3 wrote:I've been using Bmax for a few months now, and you can program it using classic BASIC style or using OOP, it's just up to you to decide.
I see no inconvenience here, and sure would help in some situations!
In order to compare 2D graphics speeds and other things, I am trying now to convert some code from PB to BMX which need a linked list to be done.
Please, can you put here some BMX small code which makes use of a linked list without using OOP code :?:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

The interview with Fred was clear on this topic: he want to keep PB a procedural language.

Question 29: Will the support of OOP in PureBasic be further extended/improved? Or will PureBasic be orientated rather at the procedural BASIC also in the future?
Fred's answer: No. It will stay a procedural BASIC, I don't plan to add class and such I think it will split the PB world in 2 classes (!): the one which have understood fully how OOP work and other which don't. Which means than you couldn't share source codes easily anymore at one place. Procedural and Object Oriented Programming are two opposite concepts and it's not a good idea to mix them in a BASIC language (which is intended for beginners...)
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

However, continuing the Fred's answer, there are some ways to do a language to support fully OOP while it remains easy to read for everybody who simply can understand a Structure only contains data, and a Class can contain data and/or procedures inside.
Only that is necessary to understand OOP.
And in fact, PB has some OOP stuff, like inheritance (with keyword 'Extend' for Structures).
My only suggest is add a new format of Structures (can be called Classes, for example) which can allow inside data types and Procedures.
PB would be the first language easy for beginners, procedural in its roots, and OOP compatible.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

I think Straker has nicely encapsulated the whole "pro" discussion and given us a classy solution, with inheritance in the links and references.

:)
@}--`--,-- A rose by any other name ..
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

You are right, Dare, I am repeating and suggesting the samething than Straker :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
gvc
New User
New User
Posts: 7
Joined: Mon Oct 31, 2005 8:03 am

Post by gvc »

You have my vote for a Class/EndClass-structure!

First of all, no-one's obliged to use it, so you can keep programming in PB as before.

A class is a structure with embeded procedures, so if you understand how structures work it's a small step to classes. By the way, is the concept of classes more difficult then, for example, using API-call's? I also wonder how to survive as a programmer on the Windows-platform without any notice of OOP? You even won't be able to use vbscript or javascript.

BASIC is a beginners language??? So, when you get more experienced you abandon BASIC and switch to another language??? After reading through a few topic's on this forum it's clear to me that's not the case. A lot of 'pros' are using BASIC, even to build commercial applications.

After 10 years of procedural programming I made the effort to learn how to use classes a few years ago. It was one of the biggest revelations as a programmer! It makes code much more reusable and easier to maintain. Why say no to such a possible advantage? Even 'script languages' support classes nowedays.

So IMHO, PB will support OOP, only the developer doesn't realize it yet :lol:

Geert
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Agree :D
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

I second that :mrgreen:

It's really sad that Fred (in his interview) clearly states:

NO CLASSES FOR PUREBASIC

His decision is simply WRONG :!:

@FRED
Please reconsider your plans.
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

I agree with the above post :).
Thanks
Truth Seeker
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Maybe stop asking for OO and consider whether opportunity knocks?

Maybe there is a market for a preprocessor for OO?

And maybe someone here will build that preprocessor and sell it like hotcakes and become filthy, stinking rich? (Or at least be able to buy a pizza or two?)

:D
@}--`--,-- A rose by any other name ..
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

I sure hope the preprocesser will be open source... But the whole point I had for adding OO to purebasic is so we can work with c++ libraries and converting of C++ code.
Thanks
Truth Seeker
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Yeah, I was being glib. But there is some truth in it too - fortunes can made when someone makes like easier for others.
@}--`--,-- A rose by any other name ..
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

I tell you again: There is already such a preprocessor available:

Go to http://members.chello.at/pure-basic-essentials/ and select "Downloads" and "Dokumente". On "Downloads" you can see a sample-code of accepted oo-code.

Kukulkan
Post Reply