Public Group

Anti-OOP (C++)

This topic is 4407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey everyone. I've been away from programming for some time now and I want to get back into it before school starts again. But I was wondering if it would be at all possible to create a decent text-based RPG without using classes and object oriented things? I realized it will probably be a royal mess, but i'd rather not mess with OOP yet. . . unless I have to. Any suggestions? Thanks!

Share on other sites
any reason why you wouldn't want to use objects? They're not that hard once you get going with them, and you don't have to go insane with them. They're a tool, but not the only way. you can mix things easy enough, use classes where you need to, and don't go over board with them.

Share on other sites
Of course it would be possible to create a text RPG or any other project without OOP. After all, its been done this way for years.
Its better you do good function-based code than bad object oriented code. But note the productivity is greater using modern approach... so consider mastering OOP at some point.

To make the game (or any other project) even in function based code you can and should use OOP ideas -

1) try to abstract as much as you can: make a struct of data and a set of functions for stuff like Room, Monster, Weapon, Player.
2) each such element should not be aware of the inner workings of another type of element - changing the workings of one should not effect the entire project.
3) Plan well what data each elemant needs and how the framework of the game activates the different elements.
4) Im sleepy now so cant think, but this list should be longer.

Iftah.

Share on other sites
Quote:
 1) try to abstract as much as you can: make a struct of data and a set of functions for stuff like Room, Monster, Weapon, Player.2) each such element should not be aware of the inner workings of another type of element - changing the workings of one should not effect the entire project.3) Plan well what data each elemant needs and how the framework of the game activates the different elements.

How is that not OOP? What do we mean when we say OOP here? The C++ syntax?

Share on other sites
Quote:
 Original post by mikemanHow is that not OOP? What do we mean when we say OOP here? The C++ syntax?

1) its not entirely OOP as it has no inheritence and no polymorphism.
2) note I did say these are OOP ideas, I didnt try to hide it.

Sometimes you need to read between the lines -
I assumed the original poster meant he masters C but not C++, so I tried to make him program some OOP style and still remain in his knowledge base.

edit: to the orignial poster -
Talroth has a point - you can try write the elements I described above as class - which is simply the structs with the data and the functions combined. Its realy not complex at all and I highly recomend it. Later on if you do learn OOP and C++ you can add inheritence and use polymorphism to farther organize your program.

Share on other sites
Quote:
Original post by Iftah
Quote:
 Original post by mikemanHow is that not OOP? What do we mean when we say OOP here? The C++ syntax?

1) its not entirely OOP as it has no inheritence and no polymorphism.
2) note I did say these are OOP ideas, I didnt try to hide it.

In my understanding - which is admitedly not perfect - inheritance and polymorphism are language feature, not OO features. You can perfectly use OO in a language that don't have these features. OO is a programming paradigm, where you differentiate data and actions. The data are represented as properties while the actions are represented by messages that are sent to the data holder (I don't use the word "message" without reason: this is the real OO terminology for C++ methods). I'm with mikeman with this one - but this is not really important because I believe that metal_kid43 used the term OOP ambiguously.

I use the OO paradigm quite extensively, even when I program in C: in this case, I will use structs to store the object properties and functions to handle them. Semantically, there is no difference between this approach and the other major OO language approach.

That said, I agree with the rest of your post: I'd suggest metal_kid43 to use the OO paradigm without the difficult syntax of the OO languages (although C# tend to be very simple; it can be a good introduction to OO languages). The paradigm itself is not very hard to understand: to simplify, we consider that everything is an object. We give them properties and actions. In fact, this is often what we do when we use a procedural language like C or pascal, but we don't give it its proper name because we often think that OOP can only be done using a OO language.

To answer to metal_kid43's question, I'd like to add that most older MUDs were written in C, so it's definitely possible to create a good, complex text RPG using a procedural language. The approach, however, is likely to be a OO-like approach, as they tend to simplify the design of such program.

HTH,

Share on other sites
Quote:
Original post by Emmanuel Deloget
Quote:
Original post by Iftah
Quote:
 Original post by mikemanHow is that not OOP? What do we mean when we say OOP here? The C++ syntax?

1) its not entirely OOP as it has no inheritence and no polymorphism.
2) note I did say these are OOP ideas, I didnt try to hide it.

In my understanding - which is admitedly not perfect - inheritance and polymorphism are language feature, not OO features. You can perfectly use OO in a language that don't have these features. OO is a programming paradigm, where you differentiate data and actions. The data are represented as properties while the actions are represented by messages that are sent to the data holder (I don't use the word "message" without reason: this is the real OO terminology for C++ methods). I'm with mikeman with this one - but this is not really important because I believe that metal_kid43 used the term OOP ambiguously.

I use the OO paradigm quite extensively, even when I program in C: in this case, I will use structs to store the object properties and functions to handle them. Semantically, there is no difference between this approach and the other major OO language approach.

That said, I agree with the rest of your post: I'd suggest metal_kid43 to use the OO paradigm without the difficult syntax of the OO languages (although C# tend to be very simple; it can be a good introduction to OO languages). The paradigm itself is not very hard to understand: to simplify, we consider that everything is an object. We give them properties and actions. In fact, this is often what we do when we use a procedural language like C or pascal, but we don't give it its proper name because we often think that OOP can only be done using a OO language.
HTH,

Well, polymorphism is a cornerstone of OOP, but inheritance isn't. It's just a way of implementing polymorphism in static-typed languanges. The thing is, in the RPG the character may hold a Weapon that can be a sword,a crossbow,a hammer,etc. and each one has different behaviour. So the OP will most definately end up doing something like this:

enum Weapon_Type{Sword,CrossBow,Hammer};struct Weapon{//stuff here...Weapon_Type type;};void Weapon_Use(Weapon *weapon){    //here goes code common for all types of weapons...    switch (weapon->type)    {      case Sword:        //handle sword here...      case CrossBow:        //handle crossbow here...      case Hammer:        //handle hammer here...    }}

which is an implementation of a polymorphism scheme.

Share on other sites
Quote:
 Original post by metal_kid43[..]I was wondering if it would be at all possible to create a decent text-based RPG without using classes and object oriented things? I realized it will probably be a royal mess, but i'd rather not mess with OOP yet. . . unless I have to.

Yes. Infact, you can create a MMORPG without any OOP design, even in a OO language (Have a look at my Fleurin project some time).

If you don't want to use OOP, you don't have to. Remember, it is a preference.

Share on other sites
If you're going to try to do anything at all complicated, you better have a good way of organizing things. OOP happens to be a good way of handling a lot of problems in the general area of "organizing things", but is certainly not the only way.

That said, what do you have *against* OOP? What do you think "OOP" *is*, anyway? o_O A lot of people have some *very* strange concepts of it...

Share on other sites
Quote:
 Original post by mikemanWell, polymorphism is a cornerstone of OOP, but inheritance isn't. It's just a way of implementing polymorphism in static-typed languanges. The thing is, in the RPG the character may hold a Weapon that can be a sword,a crossbow,a hammer,etc. and each one has different behaviour. So the OP will most definately end up doing something like this:*** Source Snippet Removed ***which is an implementation of a polymorphism scheme.

I should note that most people don't actually know OO/OOD/OOP at all, as demonstrated by the fact that most people don't even know about the 5 principles of Object Orientation. On that note however, no one with any serious design experience would write C code like that. It would be more like:
typedef struct WeaponT{    /*... stuff*/    void (*WeaponHandlerPtr)(struct WeaponT*);}Weapon;void UseWeapon(Weapon* p) {    p->WeaponHandlerPtr(p);}

1. 1
2. 2
3. 3
frob
15
4. 4
5. 5

• 20
• 12
• 13
• 14
• 80
• Forum Statistics

• Total Topics
632144
• Total Posts
3004406

×