Jump to content
  • Advertisement
Sign in to follow this  
McCoder

Are classes evil?

This topic is 3596 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

Looking at the flow of win32 api and opengl makes me wanna stick everything into classes. Is this a good practice? I would want to get so clean that I should read InitSound(); DrawStuff(); DiePainfully(); etc. Good clean code.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by McCoder
I would want to get so clean that I should read InitSound(); DrawStuff(); DiePainfully();

I fail to see the connection with classes...

Share this post


Link to post
Share on other sites
Quote:
Original post by DevFred
I fail to see the connection with classes...


my take at a translated OP: "these very popular APIs do not use classes. did they avoid them for a reason or is it ok if I encapsulate them?"

IIRC they were originally offered before OO programming was so prevalent. There's not necessarily a good reason for them to not be encapsulated in a class if you find that easier to use.

-me

Share this post


Link to post
Share on other sites
If it makes sense for your project, then absolutely encapsulate them in classes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Palidine
Quote:
Original post by DevFred
I fail to see the connection with classes...


my take at a translated OP: "these very popular APIs do not use classes. did they avoid them for a reason or is it ok if I encapsulate them?"

IIRC they were originally offered before OO programming was so prevalent. There's not necessarily a good reason for them to not be encapsulated in a class if you find that easier to use.

-me


thats what I meant, thanks :) sorry, but im not english :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Palidine
IIRC they were originally offered before OO programming was so prevalent. There's not necessarily a good reason for them to not be encapsulated in a class if you find that easier to use.

The Win32 API was written before C++ was prevalent. You can write object oriented code in C, you just need to do it without language support for classes. Ie, you would have structures and a set of functions that operate on said structures instead of just bundling it all into a class with members and member functions. If you want polymorphism you need to add extra code to handle the switching between types manually. For a list of principles that are really important to OO, read this.

Anyway, a good reason to keep the API in C is backwards compatibility and the fact that C++ doesn't have a standard way to decorate names. See this. This makes it hard to interoperate between languages. So, C is often to make it easier to bind things together.

Share this post


Link to post
Share on other sites
Quote:
Original post by nobodynews
Anyway, a good reason to keep the API in C is backwards compatibility and the fact that C++ doesn't have a standard way to decorate names. See this. This makes it hard to interoperate between languages. So, C is often to make it easier to bind things together.


Just out of curiosity, is there a reason there isn't a standard way to decorate names in C++? Seems like the world could benefit from consistent name mangling.

Share this post


Link to post
Share on other sites
Quote:
Original post by MikeTacular
Quote:
Original post by nobodynews
Anyway, a good reason to keep the API in C is backwards compatibility and the fact that C++ doesn't have a standard way to decorate names. See this. This makes it hard to interoperate between languages. So, C is often to make it easier to bind things together.


Just out of curiosity, is there a reason there isn't a standard way to decorate names in C++? Seems like the world could benefit from consistent name mangling.


If you keep reading down that page there is even the heading: "Standardised name mangling in C++".

Share this post


Link to post
Share on other sites
I would say the idea that you have is good, but please don't get carried away.
Just because you think it might need to be stuck into a class doesn't necessarily mean that it needs to be stuck into a class.

My rule of thumb when dealing with OOP is make objects, not classes, and make sure the objects are independent, and have their own responsibilities otherwise I see no use of creating them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!