Are classes evil?
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.
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...
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
Quote:Original post by PalidineQuote: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 :)
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.
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.
Quote:Original post by MikeTacularQuote: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++".
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement