OOP Support (it is time)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: OOP Support (it is time)

Post by MachineCode »

[Silly burger analogy deleted]
Last edited by MachineCode on Mon Mar 21, 2011 1:03 pm, edited 1 time in total.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
DaylightDreamer
User
User
Posts: 52
Joined: Wed Feb 04, 2009 8:11 am
Location: Armenia

Re: OOP Support (it is time)

Post by DaylightDreamer »

Looks like you right. I am......

And Gosh. Comparing Programming Language with a Burger ???....... not even close.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: OOP Support (it is time)

Post by c4s »

@DaylightDreamer
I don't know anything about OOP, but your examples really caught my interest! Do you have some tips where I can find good'n'easy tutorials to understand/learn it?
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
DaylightDreamer
User
User
Posts: 52
Joined: Wed Feb 04, 2009 8:11 am
Location: Armenia

Re: OOP Support (it is time)

Post by DaylightDreamer »

Of course.
The idea of OOP is to separate part of the code from the main code.

For example you have the request from the lead programmer to develop an enemy Object , also named Class.

The code gonna look something like like that

Code: Select all

Class enemy

    var enemy_health.l    // This variable will be visible only inside this object and will not conflict with the main program
    // and what is modified inside one function in this object later can be accessed from another function

    Procedure enemy()
        // Here We gona create our enemy, loading his models, sounds textures
    EndProcedure

    Procedure update_enemy()
        // Here We gonna update our enemy step
        //And Based on some conditions we might want to destroy ourself
    EndProcedure

    Procedure __destruct()
         // This part of code will be called any time this object is deleted by some reason
         // Here we will free our textures objects sounds    
    EndProcedure
EndClass
NONE of that will be visible in the main program.

And here how we gonna call it from the main code

Code: Select all

enemy1 = new enemy()
enemy2 = new enemy()
here we have two independent enemies

and on each frame we can call the function from inside the object

Code: Select all

enemy1.update_enemy()
enemy2.update_enemy()
This is basically it.
And of course you don't have to use all that and continue coding in procedural way.

This is basically it.
DaylightDreamer
User
User
Posts: 52
Joined: Wed Feb 04, 2009 8:11 am
Location: Armenia

Re: OOP Support (it is time)

Post by DaylightDreamer »

You can have one class name Enemy which will manage all the enemies on the stage and will free resources correctly.
Another name MainCharacter
Another named Bullet,Item,StageDecoration and so on.

And the coolest part that each Object can be developed by the separate person. And this person dont have to worry about conflicts with the main program.
Complex games are developed that way.
DaylightDreamer
User
User
Posts: 52
Joined: Wed Feb 04, 2009 8:11 am
Location: Armenia

Re: OOP Support (it is time)

Post by DaylightDreamer »

And if you have questions i will gladly answer.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: OOP Support (it is time)

Post by c4s »

Thanks, but this can't be all: Isn't all this possible in PureBasic somehow? I think I've already seen code that works that way. I just remembered a tutorial by srod, gonna read that: http://www.purecoder.net/oop.zip

I don't see why there is so much discussion for something that simple...
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
DaylightDreamer
User
User
Posts: 52
Joined: Wed Feb 04, 2009 8:11 am
Location: Armenia

Re: OOP Support (it is time)

Post by DaylightDreamer »

Well logically all this is nothing more than a Stricture with possibility to put Procedures inside.

This example is a recreation of OOP.
But with the syntax i described, on the background happens wht you see in this example.
It is simple once when you understand the theory.

I dont know if you familiar with DivGamesStudio created in Spain around 10 years ago.
There also had very interesting approach to game development.

You could create a function and this function could work in parallel with the main program.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: OOP Support (it is time)

Post by Foz »

Ok, I don't get these requests. At the end of the day, OOP has to unravel down to ASM. So why not take the step that was going to be C++? A precompiler!

Take this WORKING example in PureBasic:

Code: Select all

EnableExplicit

Class Animal
   Public Abstract Walk()
   Public Abstract Sleep()
EndClass

Class Dog Extends Animal
   Public Method Walk()
      Debug "Im Walking Very Fast! Wuff!"
   EndMethod
   
   Public Method Sleep()
      Debug "Im Sleeping Now! Wuff!"
   EndMethod
EndClass

Class Turtle Extends Animal
   Public Method Walk()
      Debug "Im Walking Very Slow! Crawl!"
   EndMethod
   
   Public Method Sleep()
      Debug "Im Sleeping Now! One Turtle, Two Turtle...!"
   EndMethod
EndClass

Class Cat Extends Animal
   Public Method Walk()
      Debug "Im Walking! Miauw!"
   EndMethod
   
   Public Method Sleep()
      Debug "Im Sleeping Now! Buzz...Buzzz!"
   EndMethod   
EndClass


NewList *Animals.Animal()

AddElement(*Animals())
   *Animals() = NewObject.Dog

AddElement(*Animals())
   *Animals() = NewObject.Turtle
   
AddElement(*Animals())
   *Animals() = NewObject.Cat

ForEach *Animals()
   *Animals()\Walk()
   *Animals()\Sleep()
Next
That's using SimpleOOP, so if you want to make it a two pass compiler, why not do the first pass yourself ?

What is this incessant request to make it the core, when it's just another programming methodology, that the solution for it *already exists* ?
DaylightDreamer
User
User
Posts: 52
Joined: Wed Feb 04, 2009 8:11 am
Location: Armenia

Re: OOP Support (it is time)

Post by DaylightDreamer »

Another very important thing it is stability.

In complex program i might create 100 or 1000 objects (explosion particles)
And after completing its animation each particle will destroy itself.

Did you play Gradius ? Remember how many moving objects do you have on the screen ?
Each one is a separate "Object,Class"
And each object destroys itself one he goes outside the screen.

If two pass precompiler can handle that without crashing i don't have problem with that.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: OOP Support (it is time)

Post by Foz »

Well, give it a go, and then tell us (and the author) how it goes. Perhaps you can march the way forward for using OOP in PureBasic.
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: OOP Support (it is time)

Post by TomS »

Thanks, Foz for your contribution.
Nice to see that anyone else but me is using SimpleOOP :D
(not to confuse anyone. I'm not the author. I just use it and think it's a great alternative to waiting for ages for everybody who wants oop in pb)

I am actually kinda used to the procedural programming. Because I never had anything else.
PB is procedural and so are the many tutorials on php (since they added oop only in version 5).
So I don't feel the need to add oop to PB. But it's a nice to have and for this purpose the precompiler does its job quite well, I think.
I'm with Foz on this one. Give it a go!
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: OOP Support (it is time)

Post by c4s »

I heard there are at least 3 good-working precompilers for PureBasic (SimpleOOP being one of them). Which one do you prefer most?

Sure every has its pros and cons but for me - as a total beginner in this matter - it's hard to differentiate them.
Any tips? Is SimpleOOP the best one? :)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: OOP Support (it is time)

Post by TomS »

I use SimpleOOP. But honestly I haven't tried the others. :oops:
I don't know which one is better. I imagine there are slight differences in syntax, or maybe not.
You could install 3 new PBs and test them yourself.
Since there seem to be only few users of oop-precomilers, profound advice on which one to take is probably very hard to find.

SimpleOOP comes with a ton of easy to understand, well documented examples that explain syntax and how to use oop with it generally.
But I think the concept of Inheritance it not fully developed. I don't know about the others.
But for getting oop to know it's as good as any.
If you find you push the limits of simpleOOP, try another one.
But that won't happen so fast, I think.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: OOP Support (it is time)

Post by Foz »

Of the others, I prefer the syntax of SimpleOOP, for one reason: procedures in the classes (I can relate to that syntax due to using VB.net at work)

I believe that if *everyone* (including the team) used the same OOP precompiler, I would think that it would be integrated into the core in short order, regardless of Feature Requests for OOP.

That said, I don't use really use OOP with PureBasic, as I prefer working procedurally.
Locked