[gameprogrammer] Re: OT: C vs. C++ (Was: Re: [SDL] Re: A question on GUIs)
- From: Chris Nystrom <cnystrom@xxxxxxxxx>
- To: "A list for developers using the SDL library. (includes SDL-announce)" <sdl@xxxxxxxxxx>, gameprogrammer@xxxxxxxxxxxxx
- Date: Mon, 26 Dec 2005 17:38:43 -0600
On 12/26/05, Clemens Kirchgatterer <clemens@xxxxxxxx> wrote:
>
> this audio lib by no means is anywhere near OO, IMHO.
I do not claim to be an expert, but I believe you are making OO more
complicated than it is.
Going by http://en.wikipedia.org/wiki/Object-oriented_programming:
"In the most general terms, OOP is the practice of writing program
text decomposed in modules that encapsulate the representation of one
data type per module..."
Basically data + methods = objects (or more accurately classes).
In C you can do this by putting your data in its own source file
(module) and making it static (private), thus encapsulating that data,
and then access the data with public functions (methods). In this way
you have complete control over access to the data. Using this
programming style you can easily create self contained modules that
can easily be taken out and used it in other projects.
> i would have
> expected you to use a struct to simulate your sound class
I would have used a structure if I believed the data needed a
structure, but structures are not the central to the definition. In
this case it I was encapsulating fairly simple data.
> and function
> pointers within this struct to have something like methods operating on
> the structs data members.
You do not need to use function pointers to create the methods to
access the data. Great if you need them, but not a requirement in my
opinion.
> and if you would have done it this way, you
> would instantly see the advantage of the C++ syntax as it hides all this
> uglyness. instead you just defined PRIVATE as static and use plain C
> procedures on an global, preallocated list of sound buffers.
No, this is important. The data is not global. The data is local
(static or private) and can only be accessed via the methods (public
functions). This is the whole point. You create an interface to the
data.
> you might argue, that using a struct for your sound objects would have
> been more complicated and overkill. you are right - but this shows, that
> it just is a rather poor example for OO code in C.
I disagree. See above. I think you might have missed the OO. I believe
you can use OO for simple objects as well complicated ones.
> > although this discussion more properly belongs on the gameprogrammer
> > mailing list.
>
> true.
Ok, I copied the gameprogrammer list. Hopefully this discussion moves there.
Chris
--
E-Mail: Chris Nystrom <cnystrom@xxxxxxxxx>
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: OT: C vs. C++ (Was: Re: [SDL] Re: A question on GUIs)
- From: Matthew Weigel
Other related posts:
- » [gameprogrammer] Re: OT: C vs. C++ (Was: Re: [SDL] Re: A question on GUIs)
- » [gameprogrammer] Re: OT: C vs. C++ (Was: Re: [SDL] Re: A question on GUIs)
- [gameprogrammer] Re: OT: C vs. C++ (Was: Re: [SDL] Re: A question on GUIs)
- From: Matthew Weigel