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

User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Hi you all,

Didelphodon posted in the german forum a oop-pre-compiler which allows you to write code like this:

Code: Select all

Class MyClass1
    attribute1.l

    Method setAttribute1(value.l)
        *this\attribute1 = value
    EndMethod

    Method.l getAttribute1()
        MethodReturn *this\attribute1
    EndMethod
EndClass

Class MyClass2 Extends MyClass1
    attribute2.l

    Method setAttribute2(value.l)
        *this\attribute2 = value
    EndMethod

    Method.l getAttribute2()
        MethodReturn *this\attribute2
    EndMethod
EndClass

NewObject *obj.MyClass2

*obj\setAttribute1(1)
*obj\setAttribute2(2)
Debug Str(*obj\getAttribute1()) + " / " + Str(*obj\getAttribute2())
*obj\destruct()

End
It is simple to use as a little precompiler before you use the pb-compiler. You can find more informations and the precompiler on the german website: http://members.chello.at/pure-basic-essentials/ (try downloads).

The site is in german, but the precompiler works very good. If there would be some good feedback on the forum or guestbook of this site, Didelphodon may extend this much more. He is paused in the moment, cause of some illness but will keep on working on this in future (i hope so).

The best thing on a way like this is, that everybody can choose if he wants to use oop or not. If it was possible to use this as an addin in the pb-ide, everyone would be happy, or not?

Kukulkan
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

does the new pb ide support plugins?
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

Post by geoff »

I am against adding OOP.

I have recent experience of javascript with DHTML. So much is implicit (or inherited) that you can't be sure if it will work, why it doesn't work or what you need to do to make it work. And when it does work you can't be sure if it is correct or a lucky coincidence that something you have omitted has taken a correct default value (or property), but will not work in different circumstances.

I think it unrealistic to expect any major addition to PB not to worsen the existing functionality. When anything becomes more complex it becomes more difficult to debug. Notice how each release of PB gets progressively more difficult to get right, notice how each release of Windows takes longer to develop. Complex things tend to be less reliable, look at the Space Shuttle.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Hi geoff.

You probably know this, but in case you dont: You can use JavaScript as a simple or functional (is that the term?) language as well as with in a heavy duty OOPish way. DHTML access to things like, say, stylesheets, require properties, etc, to set/get values, but JS in and of itself needn't have too much reliance on OOP. It had to retain old funtional approach for all the old apps that used it that way.

On the "To OOP or not to OOP" question:

Provided OOPing PB did not break what we have, it is not necessarily a bad thing. Whilst I don't think I personally would use it (the OOP bits) often, there are cases when it would be useful. Esp when dealing with external stuff that is OOPish.

However first PB needs to get it's data types out of the stone age. Even QB (DOS!) had 8 byte floats!
@}--`--,-- 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 »

Kukulkan wrote:Hi you all,

Didelphodon posted in the german forum a oop-pre-compiler which allows you to write code like this:

Code: Select all

Class MyClass1
    attribute1.l

    Method setAttribute1(value.l)
        *this\attribute1 = value
    EndMethod

    Method.l getAttribute1()
        MethodReturn *this\attribute1
    EndMethod
EndClass

Class MyClass2 Extends MyClass1
    attribute2.l

    Method setAttribute2(value.l)
        *this\attribute2 = value
    EndMethod

    Method.l getAttribute2()
        MethodReturn *this\attribute2
    EndMethod
EndClass

NewObject *obj.MyClass2

*obj\setAttribute1(1)
*obj\setAttribute2(2)
Debug Str(*obj\getAttribute1()) + " / " + Str(*obj\getAttribute2())
*obj\destruct()

End
It is simple to use as a little precompiler before you use the pb-compiler. You can find more informations and the precompiler on the german website: http://members.chello.at/pure-basic-essentials/ (try downloads).

The site is in german, but the precompiler works very good. If there would be some good feedback on the forum or guestbook of this site, Didelphodon may extend this much more. He is paused in the moment, cause of some illness but will keep on working on this in future (i hope so).

The best thing on a way like this is, that everybody can choose if he wants to use oop or not. If it was possible to use this as an addin in the pb-ide, everyone would be happy, or not?

Kukulkan
Very intresting, I tried to look at the site using WorldLingo. The IDE and precompiler that was being made there looked great. Do you think there might be a English version?
Thanks
Truth Seeker
pantsonhead
User
User
Posts: 39
Joined: Fri Mar 26, 2004 1:47 pm
Location: London, UK
Contact:

What Fred wants is fine with me

Post by pantsonhead »

I won't complain if PB never supports OOP.

I expect it would take a LOT of time and effort to implement and it will still won't be "right" for some users.

I use OOP in other langauges and when you need it, it's great.
But I haven't missed it it PB yet. If it ever did come along in PB, I would hope it was so transparent
that you could ignore it unless you decided to use it.

I'd rather Fred spent time getting OSX version finished before starting something extra like this.

I love PB for what it is now so whatever Fred wants is fine with me.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

I'd love to have PB support OO properly.

It takes a lot more than just allowing an OO style syntax to do OO.
SoulReaper
Enthusiast
Enthusiast
Posts: 372
Joined: Sun Apr 03, 2005 2:14 am
Location: England

Post by SoulReaper »

hello all :)

I voted yes the reason is pure basic is a basic and yes good for beginners and advanced - but the reason I bought it was I was looking for a next generation language and i looked at loads of differnt basics...

I believe i have found the langauge and it is called pure basic and in time it will prove itself :wink:

very few basic use machine code inline which is a big plus
just to show the power JAPBE editor is written in Pure Basic!
ok I have said enough :roll:

love beating that pure basic drum :twisted: :lol:

Kevin
porfirio
Enthusiast
Enthusiast
Posts: 111
Joined: Mon Nov 15, 2004 11:00 pm
Location: portugal

Post by porfirio »

I like very mutch pb as i like VB.NET.
The OO is very cool and gives you alot of vantages.

I would love to see a programing language like javascript
Its the most cool OO language and you can do esey classes with sub classes and vars etc.
Sadly theres no JS for programing only for scripting in webpages etc...
have you imagined this?

Code: Select all

hwnd=new Window(10,10,500,400,#pb_system_menu,"my win")
btn=new hwnd.Button(5,5,72,20,"OK")
btn.click=function(e){
   MessageRequester("My app","You clicked button")
   hwnd.title="I changed the title :p"
   btn.value="New value on the button !!"
}
That would be so cool!!
But its kinda impossible :(
Forgive-me for my english, i'm portuguese!
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

Why don't you learn real Java then its not the same but it is a good OO developing language
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

It looks like PureBaisc is never going to have OOP, so we should just stop talking about it.
I like logic, hence I dislike humans but love computers.
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

I get that feeling too :(.
Thanks
Truth Seeker
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;
Post Reply