Advantages of OOP?

Discussion in 'OT Technology' started by Zaffir, Sep 9, 2003.

  1. Zaffir

    Zaffir OT Supporter

    Joined:
    Mar 9, 2003
    Messages:
    38,275
    Likes Received:
    0
    Location:
    Seattle
    Are there any real advantages to object oriented programming? I have to learn java for one of my CS classes, and objects and classes seem to just add clutter and extra steps when compared to a language like C. I've yet to see any real reason to convince me to learn C++ and leave C behind.

    Thoughts? :hs:
     
  2. crotchfruit

    crotchfruit Guest

    "why do i need to learn C? i can just code all my programs in assembly."
     
  3. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    give this man an award! he knows where its at!
     
  4. Zaffir

    Zaffir OT Supporter

    Joined:
    Mar 9, 2003
    Messages:
    38,275
    Likes Received:
    0
    Location:
    Seattle
    Because C is easier to write in most cases, and easier to read. THat's my thought, anyways. But with C++, it seems that objects make it HARDER to understand what's going on.
     
    Last edited: Sep 10, 2003
  5. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    my thoughts 2 u = :ugh:
     
  6. Zaffir

    Zaffir OT Supporter

    Joined:
    Mar 9, 2003
    Messages:
    38,275
    Likes Received:
    0
    Location:
    Seattle
    I can't even get a decent answer outside of the "Off Topic" forum? Jebus. I'm asking to be informed, and i get a bunch of useless crap. Is this forum a bunch of C++ nazis or something? I'm not even flaming your language, i just don't know why it's b etter, and am asking to be told why. Is that so hard?
     
  7. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
    Zaffir: It's all a matter of preference and need. Object-Oriented languages are best-suited for large scale projects and are, for the most part, general-purpose languages. Languages like Perl or SML have specific purposes and are much better suited for certain needs than C++ or Java... In your case of C vs. C++, it again depends. C was developed to do systems programming (including OS implementation). I really don't like the idea of large application systems being written in C (but that's just personal preference). And even now, there is a strong trend towards operating systems being written in OO fashion. Modern microkernel architectures actually have a lot in common with OO structure.

    IMO, what OO gives you is organization. I've never worked with any software systems with millions of lines of code. However, I've built systems with 10's of thousands of lines of code with 100-200 classes. I would not want to deal with such a system in a non-OO language. OO provides a psuedo-standard structure that is common through all the languages in the family which makes it universally understandable.

    I also find it easier to jump into a OO system that I haven't written. Just last week, I analysed a system my friend was given to handle. She's working with an 80 class (20,000+ lines of code) system developed by a few other people. Within 2 hours, we knew exactly what was going on. I don't think it would be as easy to do that without a similar highly-structured system. Again, if you think non-OO systems provide enough structure, then that's cool... It's preference. Just stating my opinion.

    Also, on the flipside, I've been to lectures given by senior developers at Computer Associates and some have said that OO systems require much more time and effort to maintain than non-OO systems. That seems contrary to what I've learned in academia but I'll entertain the thought at least. I don't recall specific statistics nor can I find any highly-relevant studies on the web to back this up though.

    Either way, it all depends on preference and what tool is best suited for the job... If you haven't been exposed to OO yet, I would assume you're either really old or you haven't had much experience programming. I would keep an open mind. Close-mindedness or "fear" of new things isn't good for this field.
     
  8. Divine Vengeance

    Divine Vengeance New Member

    Joined:
    May 21, 2003
    Messages:
    20,453
    Likes Received:
    0
    I agree with Nocera, OOP has its upsides and downsides depending on the language and the application its being used in/for. Since I mainly do PHP, I find OOP to be a waste of time. Using it in my CS course with Java is a completely different story however, but perhaps that's because how I was taught to program in Java. Matinence-wise, OOP is much easier to implement changes through an entire project quickly than it is a large number of individual files.

    It really comes down to a matter of personal preference and future organization and matience.
     
  9. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    What differs from OOP languages and procedural languages are Inheritence, Polymoprhism, Encapsulation, and object/class environment.

    The benifits of this over procedural languages is many things. If you're working on a large project, It would be much easier to work in an Object Oriented environment because you will be working with a lot of code. This will give you more structure, and it will also enable you to reuse code (using objects, without having to rewrite the same lines multiple times). Which you cannot, in procedural languages. Also good for maintanance (This is why most companies work with OOP languages other than Procedural). Data hiding is one of the popular benifits of OOP languages. It's ability to hide data from the user, which cannot be done in structural programming languages.

    OOP isn't a waste of time. I find it easier to develop under an object oriented environment. I also find it easier to maintain/upgrade current projects without having to search through hundreds of lines of code.

    That's my two cents anyway.

    OOP > Procedural
     
  10. lavaca45

    lavaca45 Guest

    Okay, I have no life, but I hope this helps.


    I more familiar with C++, but I expect that most of what I say will apply to Java as well. Also, I'm not very familiar with C, so if I say something incorrect about it, feel free to correct me. There are two advantages to OOP in general and another two for C++ in particular.

    The first advantage is a conceptual one: some people find it easier to think in terms of objects with properties (data members) and associated operations (methods). The idea of encapsulation and private data members also helps to create stabler objects. Compare the number of times poorly used char arrays/pointers cause problems in a C program with the string class in C++. Has anyone EVER had a problem with a string? I know I haven't. I doubt I could break one if I tried.

    The second advantage is the posibility for hierarchies of objects. Inheritance and Polymorphism work wonders on certain types of applications -- especially when coupled with parameterized containers. Consider the following:

    list <widget*> drawables; // create a list of widget pointers

    drawables.push_back(new button);
    drawables.push_back(new window);
    drawables.push_back(new scrollbar);
    // Add several kinds of widgets to the list.

    for (int i = 0; i < drawables.size(); ++i)
    drawables->draw(); // Draw all of these widgets

    To get similar functionality to that in C, you'd have to use void pointers and switch statements. These switch statements would have to be updated everywhere in the application every time you added a new type. In C++, the compiler handles all those details for you. Furthermore, the C++ method is type-safe. Can you imagine doing the above with C? For large widget type lists, the switch statement could span a hundred lines! In every place that you dereference your pointer!

    A third thing about C++ as an OOP language is constructors and destructors. Objects are capable of handling their own initialization (allocating memory, entering a known state) and deinitialization (deallocating memory, usually). When an object is created, it sets itself up. When an object goes out of scope, it cleans up after itself. Properly written C++ code can virtually guarantee an end to memory leaks (although obviously C can also attain this ideal, C++ has these tools built-in to make it easier).

    The final thing I can think of off the top of my head is probably more than enough alone to justify C++ in my mind: the Standard Template Library. C++ comes with a whole set of objects for almost every occasion. They handle their own memory, they're usually general enough to be used with any other object types (even custom ones), and they're probably more efficient than anything I could come up with when I have a deadline. This might not be a tremendous benefit to someone who has a large personal toolbelt (stacks, queues, linked lists, etc), but it certainly speeds up development time for every one else. Also, these objects are common to everyone using your version of the library, and you can count on them being there on any system with a conforming C++ development environment.

    I personallly think that both C and C++ have their places, but I'm definately biased toward C++. It's more complicated than C, but that's because it's more powerful as well. I'm relatively sure most of this also applies to Java.

    Corrections? Comments? Flames? This turned out to be a lot larger than I intended for it to be. : \
     
  11. Zaffir

    Zaffir OT Supporter

    Joined:
    Mar 9, 2003
    Messages:
    38,275
    Likes Received:
    0
    Location:
    Seattle
    Thanks for the serious replies. They've helped my understanding quite a bit.

    I'm a pretty newbie programmer. I've done pretty much all C (and a little visual basic, but i wouldn't consider that real programming), and this Java course is my first introduction to OOP. I'm frustrated right now because the programs we've been writing would be much easier and simpler in a procedural language, or at least that's how i feel. As you said OOP is good for large scale projects, and what we're doing certainly isn't large scale.

    I've yet to have a really good explanation of what objects and classes are and really do and how they do these things. Part of that might be my prof - she's pretty inexperienced and doesn't explain things well - and part of it might be the book, or even just me; i had a problem with pointers for a long time until someone explained them in a "better" way and i went "oh, that's all they are? Well shit." I might just need one of those "ah-hah!" moments at 3:00 AM to get it set in my brain. In the time since starting this thread, I've been doing some reading and looking for better explanations of OOP concepts, and I'm beginning to get it. For this little shit we're doing now i pine for C, but later on i can see OOP being advantagous.

    I certainly want to keep an open mind. Most programmers have forgotten more than I know, so it'd be pretty stupid of me to jump to conclusions. And that's why i came here - I saw OOP as something bloated and ugly, and wanted to see what I was missing.

    Thanks again.
     
  12. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    I think Nocera pretty much nailed this thread. I agree 100%. I personally enjoy OOP because of the organization and modular development process. As Nocera said, it is easier to figure out how things work. I can also confirm from my own experiences that understanding the code is easier.
     

Share This Page