Jump to content
  • Advertisement

Archived

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

farmersckn

Classes Vs. Straight Code

This topic is 6674 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, which is faster, using classes, or using straight code? I''m not talking about using MFC to write a game or anything, cuz I know that hardly anyone does that. But isn''t it just that little bit slower because you have to pass the ''this'' pointer to every method? Another thing, is it really as easy to write a program using classes as it is to write code like you would in C? Or is it easier? farmersckn Sometimes even chickens need to eat... Don't bang your head against a wall just to enjoy the good feeling when you stop.

Share this post


Link to post
Share on other sites
Advertisement
''C'' may be a bit faster but working with classes is a lot easier. As to the MFC, i wouldn''t make a game with it but i have made some 3D programming tools with it and have experienced no performance penalties. MFC is simply a thin wrapper around the Win32 API.



ECKILLER

Share this post


Link to post
Share on other sites
> which is faster, using classes, or using straight code?

Impossible to answer. :-)

> But isn''t it just that little bit slower because you have to pass the ''this'' pointer to every method?

If you don''t use classes (and thus the hidden "this" pointer), you''d end up having to dereference a pointer, or pass an extra pointer yourself anyway. Besides, if passing an additional single pointer is producing a significant slow-down in performace, something''s wrong with your design. Or try inline. :-)

> Another thing, is it really as easy to write a program using classes as it is to write code like you would in C? Or is it easier?

I used to be an "only C" programmer. When I started learning C++, it took me a couple months to really get the hang of things. Now, for me, I have trouble thinking of how to approach a programming problem *without* using classes. But that''s the nice thing about C++ - as you''re learning it, you can still use as much "only C" as you want to minimize the learning curve.

the Gent

Share this post


Link to post
Share on other sites
I personally don''t like over doing classes. Sure they r cool, but not for everything like a CApp. I love nice clean C code (i usually compil as cpp tho ), its so nice to look at! The speed diff is almost nothing tho.

quote:

from ECKILLER
''C'' may be a bit faster but working with classes is a lot easier.



IMO, if you have well designed C app its just as easy...



-----------------------------
-cow_in_the_well

http://cowswell.gda.ods.org/

Share this post


Link to post
Share on other sites
Which is faster? Hmm, depends. That''s a loaded question. Questions that come to mind is:

How long will it take to make it procedural top down? Object Oriented?

How easy will it be to maintain?

How easy will it be to integrate new concepts in?

Most importantly, will it get finished top-down or OO?

Just because it''s C++ doesn''t mean everything has to be a class either by the way. Use what works for you on the situation at hand, that''s what I would say.

YAP YFIO,
deadlinegrunt

Share this post


Link to post
Share on other sites
quote:
Original post by deadlinegrunt

Just because it''s C++ doesn''t mean everything has to be a class either by the way


I know that, and as I said I compile using the CPP compiler in MSVC rather than the C, so i can take advantage of keywords such as new and delete. I just don''t like the over usage of classes some people use. (ie. u don''t need classes on things u don''t need multiinherited (such as the CApp example)).





-----------------------------
-cow_in_the_well

http://cowswell.gda.ods.org/

Share this post


Link to post
Share on other sites
C & C++ 'speed' is the same.
It is what you use, do not use, or simulate that makes the difference.

If you use a table of function pointers in C, you may as well use a C++ class. If you use name-mangling in C, you may as well use Operator overloading in C++.

If you're not maxing out the computing power of the machine; there's no need to optimize.


Edited by - Magmai Kai Holmlor on June 28, 2000 9:54:37 PM

Share this post


Link to post
Share on other sites
Well, I don''t know too much about C++, but I prefer straight C. There are some nice things about C++, such as operator overloading and `new'' and `delete'', but I don''t think classes are as useful as everyone makes them out to be. How often would one need multiple instances of a module, anyway? What the heck is the difference between w_move(win, x, y) and win->move(x, y)? Besides the fact that the latter is slower?

I have a sneaking suspicion that all that is the stuff mindless babbling rants are made of, not solid code. So it depends on what your goal is: to babble about your `superior'' methodologies, or to simply wallop the snot out of the competition.

Now, now. I don''t mean to insult anyone. It''s just that I''ve taken way too much C-is-insufficient-for-Real-Programs hogwash.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!