Sign in to follow this  

C++

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know this might be a silly question because I myself Like C++. I’ve been thinking about creating DLLs that contain the interfaces to the various DirectX APIs I use. But why build classes to contain the functionality that you use? That’s pretty much the same this as use DirectX with out wrapping it isn’t Give or take a few additions and modifications to make things easier. If anything, just use regular old C functions. That way you don’t have nasty C++ class code laying around such as object->method( parameters ) when you can just do function( parameters ). If nothing else, use structures that hold a bunch of function pointer. Sort of like a namespace, but instead, the structure is initializes when you call a global function that returns that structure to you. Something like GetGlobalInterface( ); similar to the LightWave SDK. That seams easier to me then playing exporting classes (all though it’s not that hard to export a class) that encapsulate everything. When I think about it, what is the class doing anyways? The same thing I would be doing with out a class: calling functions and editing manipulating data some how. The only things I get out of my classes are encapsulation or polymorphisms. I know C++ classes work good for a lot of things, but so do structures. I’m not trying to say witch language is better, but I get really sick and tired of dealing with C++ class bullshit. I like to make things easy to access and use. Classes are easy to use to but so are functions and structures. The cool thing I like about C++ is that it allows the use of functions in structures and it’s built in memory management (you know... new and delete). This probably sounds like a framework issue or something like that, and it is. I just don’t get why I should build a class to encapsulate other objects that will do the same thing as the object that have been encapsulated. It seams like I’m just making a copy of a copy of a copy and so on. It’s very frustrating and annoying. What are you suppose to do when you come to a blockade like this?

Share this post


Link to post
Share on other sites

  1. Learn some grammar
  2. Both are suited to different things. C is brilliant for prototyping and small apps, whereas C++ is good (not prefect) for event based communication systems, where you can't exactly model the flow of data perfectly, so instead you forget it and imagine discrete sets of data.

C is imagining the flow, C++ is creating sets of things.


I would research into Guards, Events and Transitions.

Share this post


Link to post
Share on other sites
Learn to accept it?
Realize that OOP isn't meant to do things that are impossible to do in non-OOP languages. It largely just changes the perspective of design and development, and for some people and some projects, this new perspective is much easier to work with.

Switch to another API, like OpenGL?
If you're highly comfortable with a procedural style of design and development, and you're also just as efficient and reliable with procedural as a person who is skilled with OOP is when using OOP, then by all means, use the procedural style instead, and choose APIs accordingly, when possible. In fact, I'm pretty sure that you can get DirectX to work without OOP; it's just not as pretty. Maybe that's only in older versions, but I remember seeing examples of DirectX in C, not C++.

Write your own 3D engine?
If you're really desperate and/or bored and/or want a good learning experience, I suppose.

Share this post


Link to post
Share on other sites
Quote:
Original post by sakky
That way you don’t have nasty C++ class code laying around such as object->method( parameters ) when you can just do function( parameters ).

I don't find this nasty :)

Quote:
Original post by sakky
When I think about it, what is the class doing anyways? The same thing I would be doing with out a class: calling functions and editing manipulating data some how. The only things I get out of my classes are encapsulation or polymorphisms.


I think you missed the point of C++. The goal of C++ is to help you to write better code. By better code, I mean: easier to maintain, easier to debug, easier to understand. The is no such thing like 'what is the class doing': it does what it documents, and you don't have to worry about the actual implementation.

Of course, you can do the same thing without using classes. You can do whatever you want using assembly programming.

Quote:
Original post by sakky
I know C++ classes work good for a lot of things, but so do structures. I’m not trying to say witch language is better, but I get really sick and tired of dealing with C++ class bullshit. I like to make things easy to access and use. Classes are easy to use to but so are functions and structures.

Well, an object is not a fancy structure. There is a philosophy behind OO programming. It gives you directions to follow in order to do efficient data management (not processor time efficient, but rather programmer time efficient). Plain structures allow you to do whatever you want - you can even do programs which work :)

Quote:
Original post by sakky
The cool thing I like about C++ is that it allows the use of functions in structures and it’s built in memory management (you know... new and delete).

They are built-in C++ thingies - just as malloc() and free() are builtin C thingies. If you don't use constructores (because you don't want to use classes), you'll find no interest in new and delete. More, you'll find them error prone, because you actually have two delete operators (delete and delete []) while you only have one free() function.

Quote:
Original post by sakky
just don’t get why I should build a class to encapsulate other objects that will do the same thing as the object that have been encapsulated. It seams like I’m just making a copy of a copy of a copy and so on. It’s very frustrating and annoying.

Encapsulation of encapsulation :) Of course, this is pointless - unless you a)encapsulate more than one object or b)enhance the behavior of the base object. (b) is actually fgailry common. After all, what are you doing? You are trying to encapsulate a DX object in order to use it using your own functions. That's exactly the same.

Quote:
Original post by sakky
What are you suppose to do when you come to a blockade like this?

I did. Then I realize the true power of OOP. Design, reuse, fast but correct coding, efficiency, and so on.

If you don't feel comfortable with C++ then I believe you should stop using it during some time. Then you'll begint to see patterns in your own code, you'll think to your objects as objects, and you'll return to C++ with more understanding of what does this language really do.

HTH,

Share this post


Link to post
Share on other sites
Just to let you know, a class *IS* a struct. This is perfectly valid in C++, but NOT in C:

typedef struct {
int x;
char a;
int doSomethingSpecial(){
printf("Something Special!\n");
}
}SpecialClass;



But I know what you mean. After playing around in C for so long, I've stopped using classes. None the less, classes have their place, but can be easily replaced by structures with external methods.

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
Well, an object is not a fancy structure. There is a philosophy behind OO programming. It gives you directions to follow in order to do efficient data management

Exactly so. OOP isn't magic, it just helps write programms that are a little bit easier to understand.

"object->method( parameters )" makes any OO language closer (to some extent, certainly) to natural language. We have neatly organized subject, predicate and optional objects. It makes easier to think about programs IMHO.

Nevertheless classes help to localize your functions so they will no longer be in global namespace. It's not the only way to prevent name collisions but it is very common.

Share this post


Link to post
Share on other sites
Hello,

Quote:
Original post by Gorax
Just to let you know, a class *IS* a struct. This is perfectly valid in C++, but NOT in C:
*** Source Snippet Removed ***
But I know what you mean. After playing around in C for so long, I've stopped using classes. None the less, classes have their place, but can be easily replaced by structures with external methods.


Of course you can. There is no difference between:

object->doSomething();

And

doSomething(&object);

If you compare the langage themselves, then you should know that C doesn't have builtin RTTI, neither it haves templates, neither it haves builtin polymorphism.

The problem is not using classes or not using classes (or, for that matters, using C++ things vs not using them). It is more using OOP vs. using procedural programming. Professional programmers have used procedural programming for years before they moved to OOP. Since OOP doesn't look like "da last fancy stuff", I believe we should understand two things:

1) procedural programming works.
2) OOP works even better :)

Regards,

Share this post


Link to post
Share on other sites
Quote:
I just don’t get why I should build a class to encapsulate other objects that will do the same thing as the object that have been encapsulated.

We call it "over-engineering."

A class should abstract a set of data and concepts such that it does not bog down the person using it with unnecessary details. It sounds like you don't have a solid foundation in using OOP - it takes a lot of time, and there's a certain Zen to it. I've made great strides, but the only way to know good OOP is to study examples of it.

Procedural programming, by contrast, encourages programmers to just write out code. OOP lends itself to architecting code, which, initially, isn't always as 'fun.'

Oh, and I have to second the grammar comment.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this