Thread: C vrs OOP

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158

    C vrs OOP

    Maxorators sig cought my eye...
    Quote Originally Posted by max's sig
    C: EatThis(pointer); OOP: pointer->EatThis(); Revolutional.... NOT.
    I have noticed that while most people make classes with functions built in to handle stuff. I usually do it the C way, use a struct, and pass it's pointer to seperate handling functions, much like window handles work. Is this like a bad thing to so or somthing, why did the thing about putting handling functions in classes ever become 'standard'?

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I think he meant "Revolutional...NOT a word".

    And I think it's just two different ways of looking at it. C comes from the idea that you have functions that control the data, while OOP has the data controlling itself, providing an interface to others on how it should be used.
    Last edited by indigo0086; 08-13-2007 at 12:58 PM.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I think people like classes because then everything is declared in one place (inside the class element) and that the definitions of those functions have the ClassName:: in front of them. That way people can easily see what is what. Classes do have some special features but all of them can be done without classes by using some creativity. What I wanted to say was not that classes are bad or anything, I just wanted to say they're not so much different from the ordinary C-style and OOP should not be worshipped as it was something revolutional. It's just an alternative way with some extra features.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Quote Originally Posted by maxorator View Post
    I just wanted to say they're not so much different from the ordinary C-style and OOP should not be worshipped as it was something revolutional. It's just an alternative way with some extra features.
    Hmm, I'm going to have to strongly disagree with this.

    First, OOP and "C-Style" (Procedural programming) are quite different. While OOP should not be worshipped (nothing should be worshipped. imo), it definately WAS something revolutionary when it was introduced, because it solved MANY problems that programmers were facing with large code bases back in the day.

    It's just an alternative way with some extra features
    In a way, yes. We could also say the same about C to some assembler language. Can anyone say that C was not a revolutionary step from assembly?

  5. #5
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I use openGL and have to use both ways, while the C style stuff is ususally bound to the OpenGL specific stuff, I put everything that uses the openGL in classes, seperating them by what they do, and encapsulating it as such. I think when using a library such as that which has no object oriented point of view, and a lot of the declaring handlers, pointers, and modifying them using functions, I find it a lot easier to use by creating objects.

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by indigo0086 View Post
    I use openGL and have to use both ways, while the C style stuff is ususally bound to the OpenGL specific stuff, I put everything that uses the openGL in classes, seperating them by what they do, and encapsulating it as such. I think when using a library such as that which has no object oriented point of view, and a lot of the declaring handlers, pointers, and modifying them using functions, I find it a lot easier to use by creating objects.
    Exactly my point. When C-style seems to get too messed up to understand anything, you can use classes. And it isn't bad to do it C-style - it's about how you like it.

    Indigo0086, you just made your 1000th post!
    Last edited by maxorator; 08-13-2007 at 01:14 PM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  7. #7
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    There is so much more to classes than just hiding the implementation.

    What about inheritance, virtual functions, etc. Now these things used in excess are not needed, but in my experience these things are very useful.

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Derived classes indeed simplify things, but there is also a C alternative - include the other struct in the new struct. So there is nothing you can't do in C, just that in C it does not look so straight-forward.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  9. #9
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    It sounds more like you're comparing C and C++ than comparing C programming with object oriented programming (which seem to me like apples and oranges).

    >Derived classes indeed simplify things, but there is also a C alternative - include the other struct in the new struct.

    Yes, so you'd be implementing an aspect of OO--just in an ugly way. So what's your point? Obviously you can use OOP concepts in C, but you say it doesn't provide an advantage.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  10. #10
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    C++ is a bad framework for OOP discussions. If you want to discuss the merits of OO and whether it is a 'revolution', consider the task of taking a Java Application into an Applet, and consider how hard that would be to do without Java's run-time polymorphism facilities.

    More importantly, the distinguishing (imo) features of C++ really don't have anything to do with OO. The following is a paper written by Bjarne Strostrup entitled "Why C++ is not just an Object-Oriented Language"
    http://www.research.att.com/~bs/oopsla.pdf
    Callou collei we'll code the way
    Of prime numbers and pings!

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Actually, maxorator's signature is just referring to syntactic sugar. That, of course, is very much language dependent and not revolutionary at all (though it may make things more fun/easy/messy/silly etc).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    I'd argue that saying OOP in C++ isn't a huge step over emulation of it in C using structs, functions, structs within structs (it will really start to get to be a big pain and mess with a large project), is like saying that C isn't a revolution over ASM, because all the nice constructs can be implemented with memory offsets, along with JMPs and CMPs.

    Of course you can implement one paradigm inside another, after all, it all boils down to some hex, but a concept makes a difference when the average programmer can take advantage of it
    Programming Your Mom. http://www.dandongs.com/

  13. #13
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    The advantage of C compared to asm is portability. C++ compared to C doesn't have that advantage.

    C is kind of like a portable ASM.

  14. #14
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Quote Originally Posted by robwhit View Post
    The advantage of C compared to asm is portability. C++ compared to C doesn't have that advantage.
    No, there is more than one advantage here. Portability is not "THE" advantage. Some other advantages include: production time, maintainability, and maintenance costs. Also, C is only portable only if some C compiler has been written in assembly on the base architecture.

  15. #15
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by MacNilly View Post
    No, there is more than one advantage here. Portability is not "THE" advantage. Some other advantages include: production time, maintainability, and maintenance costs. Also, C is only portable only if some C compiler has been written in assembly on the base architecture.
    I agree with you on that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP flu
    By Hussain Hani in forum General Discussions
    Replies: 15
    Last Post: 06-27-2009, 02:02 AM
  2. Should OOP be any new language priority??
    By Hussain Hani in forum General Discussions
    Replies: 80
    Last Post: 06-13-2009, 10:56 AM
  3. Data Mapping and Moving Relationships
    By Mario F. in forum Tech Board
    Replies: 7
    Last Post: 12-14-2006, 10:32 AM
  4. recommendation for a good OOP book
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2006, 04:28 PM
  5. OOP Theory Question
    By Zeusbwr in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2005, 08:37 AM