Basic OOP theory question
Alright, I''m stumped. Maybe you guys can help me out here.
I was brought up on structured programming (condolences can go elsewhere, heh). Then a few years ago I began to fiddle with C++. Now, I understand how to use classes and such - specifically for DirectX and OpenGL, but the theory in general. My question is why are they held in all-fired esteem? I''ve yet to see anything that REQUIRES a class or classes to do. Yet everyone says "if it''s not object-oriented it''s crap."
I''m confused at this. Can you tell? I can do the same thing in C++ with classes that I can do without classes. They''re useful in some circumstances, but never required.
you don''t have to use classes if you don''t want to. the reason alot of people use them is because its easier to mantain and reuse code.
doh, nuts. Mmmm... donuts
My website
doh, nuts. Mmmm... donuts
My website
Something like 60-80% of the software cycle is spent maintaining the code. That is fixing bugs and adding new features. This means time and money, and by using OOP, the software is much more structured and easy to maintain. Yes you can write robust software without using OO design. It simply makes it much easier though.
What do you define as "easier?" Code written in well-defined file sets that don''t rely on others except for argument-passing is as reusable as classes. After all, I segment my code like mad anyway (~10 cpp files for a 3d, computer-opponent Tetris game =) )
Potentially you can write all your code in assembly, since anyway higher level code that you write is compiled into it.
The thing is all about design theories. By definition C++ is slower than C (and ofcourse assembly), but you still find tons of programmers using it. The answer lies within the safer and more intuitive design of OOP. Theortically your code will be much clearer (to humans), reusable, easier to change etc.
Don''t bother to look for performance enhancment, cause as I said, the opposite is the truth.
Cheers.
The thing is all about design theories. By definition C++ is slower than C (and ofcourse assembly), but you still find tons of programmers using it. The answer lies within the safer and more intuitive design of OOP. Theortically your code will be much clearer (to humans), reusable, easier to change etc.
Don''t bother to look for performance enhancment, cause as I said, the opposite is the truth.
Cheers.
Of course they are not required, a chainsaw is not required to fell a tree. You can do it with an axe or even a knife. They are just a tool to help you get things done in an object oriented way. Classes helps you with issues like encapsulation, object thinking, code reusability etc. Use or abuse, its your choice.
- Benny -
- Benny -
I''m not worried about speed, I just don''t see why everyone says that code that doesn''t use classes is crap. I mean, my CS teacher - yes, CS teachers are mostly incompetent, but this was a good argument - said that code without classes is bad and should never be used. Argued that one for an hour or so. (And since I''m supposed to be in class, I''ll probably check this post again pretty soon.)
quote:Original post by Edward Ropple
I''ve yet to see anything that REQUIRES a class or classes to do.
You''ve yet to see anything that REQUIRES a function, right? The point isn''t that classes are required for writing correct software, but that classes can be useful in modelling various problem domain concepts. For example, if you wished to model an Abstract Data Type such as a linked-list, the class mechanism provides benefits over the equivalent C approach, in that you get certain functions for free (generated by the C++ compiler), you don''t need to pass around an explicit `this'' parameter, and you can create member functions to help ensure encapsulation of the concept.
OO is really about having a unified means of manipulating objects. C++ provides a means of organising classes into hierarchies in order to achieve some sort of uniformity (via inheritance), although it is very restricted in that regard. Still, C completely lacks mechanisms for doing that, which means those programs that would benefit from classes will be more verbose in C than in C++ through having to simulate the concepts.
quote:
Yet everyone says "if it''s not object-oriented it''s crap."
No they don''t.
quote:
I''m confused at this. Can you tell? I can do the same thing in C++ with classes that I can do without classes. They''re useful in some circumstances, but never required.
Right. They''re `useful in some circumstances''. What else would you expect?
quote:Original post by adiash
By definition C++ is slower than C (and ofcourse assembly)
The difference between C++ and C, by definition of the languages, is that C has fewer constructs than C++, meaning that some set of programs expressed in C are more verbose in their representation than in C++. There''s no definition which tells us explicit expression of a concept in C will run faster than the compiler-generated equivalent in C++.
OOP is an option, not a necessity. If a programmer is comfortable with plain vanilla procedural code over OO-based code, then by all means they shud follow thru to their liking. I think wat u shud do is go tell ur CS lecturer that OO isn''t everything
Personally, I like OOP coz of encapsulation and inheritance. Very useful if u get to understand their benefits, and especially useful if u start to design software from a ''normal'' persons'' point of view as opposed to a real programmer. I believe the OO paradigm is suited for ppl to visualize code in a more human-friendly way.. at least it is the case when designing the different modules of a program and how they interact with each other.
Of course, as I said, OO ain''t everything. Sometimes, u just know that procedural is the way to go. Which is y i get the creeps with Java sometimes... even the entry point needs to be in a class.. eek!
Personally, I like OOP coz of encapsulation and inheritance. Very useful if u get to understand their benefits, and especially useful if u start to design software from a ''normal'' persons'' point of view as opposed to a real programmer. I believe the OO paradigm is suited for ppl to visualize code in a more human-friendly way.. at least it is the case when designing the different modules of a program and how they interact with each other.
Of course, as I said, OO ain''t everything. Sometimes, u just know that procedural is the way to go. Which is y i get the creeps with Java sometimes... even the entry point needs to be in a class.. eek!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement