Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

EdR

Basic OOP theory question

This topic is 5656 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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 =) )

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 -

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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++.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!