Archived

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

tad pole

Is there anything wrong with just using plain old C?

Recommended Posts

Is there anything wrong with just learning all the funcionality of the C programming language as opposed to learning oo programming? The univeristy that I go to doesnt offer C++ programming classes. They structure their courses around java but also offer C programming classes. I am not a Comp Sci major but I do want to take a few programming classes just for fun. Will you eventually run into limitations just using C for OpenGL and game programming as opposed to using an object oriented language? Thanks

Share this post


Link to post
Share on other sites
C can do anything C++ can do. It just might take longer, and be a tad more error prone. The original C++ compilers output C code. :D

Share this post


Link to post
Share on other sites
Well, everything is moving towards OOP. C isn''t safe, and takes longer to make medium to large sized projects.

Share this post


Link to post
Share on other sites
Is there anything wrong with just using plain old C?

No.

Is there anything wrong with just learning all the funcionality of the C programming language as opposed to learning oo programming?

If you want to get a job, you'll need to have whatever skills recruiters want. (ok, you're not a CS major, but still).

Will you eventually run into limitations just using C for OpenGL and game programming as opposed to using an object oriented language?

Not really. However, as you add to it, your code may evolve object-oriented features, at which point using a language that natively support them is preferable to doing it all by hand. Once your game entities start growing type codes, and your functions get peppered with type switch tables, you'll soon yearn for compiler-managed RTTI

The more you know, the more options you have and the more chances you'll find the right tool, be it procedural, logic, functional, object-oriented, generic programming or something else.

Anyway, learn python, okay ?


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan


[edited by - Fruny on April 21, 2004 8:03:50 PM]

Share this post


Link to post
Share on other sites
My advice would be to learn Java, that way you get OOP experience and it is very easy to migrate to C++ using online tutorials, books, etc.

Edit: or learn Python like Fruny suggests, but with Java you can do that course at uni.

[edited by - henrym on April 21, 2004 8:05:36 PM]

Share this post


Link to post
Share on other sites
Well I am not very interested in learning Python and I kinda wanna stick to C becuase that is what the univeristy offers. I could take a java class but they also require you to take seperate labs that go along with them. I dont wanna get involved in all that to tell you the truth because that is not my major and I dont want that to take center stage in front of courses for my major. The java classes are also restricted courses so I am not even sure if they would let me in without being a CS major or minor.

I made the mistake of taking all my gen ed courses before picking a major so know I am stuck taking all the hard courses with no gen eds to break up my day and make it a little easier. That is one reason I dont wanna take java and then have to sign up for the lab that goes with it. If they would even let me in that is.

Share this post


Link to post
Share on other sites
oh and I should add that after next week I will be done with a CS class. It is good old QBasic! :/

If you come to the school and cant write a program with certain specs in any language they make you take qbasic to make you familiar with certain programming concepts. I think I have an A in the class so far so I am not totally unfamiliar with all programming concepts.

Share this post


Link to post
Share on other sites
If C is all they offer as ''casual'' programming courses, well, sure, why not. I need to caution you though that it''s not the friendliest of languages and that some of its idioms can be hard to shake off later (just look at how many people stick with char* in spite of the headaches it gives them). As you go, keep your mind open to other ways of doing things.

And IMHO, given that you''ve already successfully been through a programming class, you ought to be able to pick up Python by yourself with very little trouble (it even has OpenGL bindings )


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

Share this post


Link to post
Share on other sites
quote:
Original post by PlayGGY
With C, it will be a lot harder making more advanced programs.


Hogwash. Just because C lacks built-in OO features doesn''t make software implementation, advanced or otherwuse, any more difficult than in C++ or Java. More time consuming for both development and maintenance, perhaps, but certainly not more difficult. The problems you solve are the same.

Share this post


Link to post
Share on other sites
quote:
Original post by Aldacron
More time consuming for both development and maintenance, perhaps, but certainly not more difficult.


Multiple inheritance (no flames, please, I know it''s controversial ) is a bitch to implement.

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
quote:
Original post by Aldacron
More time consuming for both development and maintenance, perhaps, but certainly not more difficult.


Multiple inheritance (no flames, please, I know it''s controversial ) is a bitch to implement.


O_o what does that mean? It is an argument against C?
hehe you lost me on that one.


Share this post


Link to post
Share on other sites
I do beleive that John Carmack is still writting the Doom3 engine in C rather then C++ as he has with the older engines. I would say it is good to know both though.

~Wave

Share this post


Link to post
Share on other sites
think of it as the qoute by CodeDemon:
(not verbatim)
"With C its easy to shoot yourself in the foot. C++ made it harder, but when you do, you blow your whole leg off."

Sorry CodeDemon if i slaughtered your qoute

[edited by - Rocket05 on April 21, 2004 8:43:04 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
Multiple inheritance (no flames, please, I know it''s controversial ) is a bitch to implement.
I''m curious to know why it''s so hard to implement. Can you link me to an explanation?

Share this post


Link to post
Share on other sites
quote:
Original post by tad pole
O_o what does that mean? It is an argument against C?
hehe you lost me on that one.


With friends, we had a talk about how C++ multiple inheritance was done, and how we would actually go and do it in C. We did a bit of back-of-the-envelope design, pieced together some data structures and functions ... and came to the conclusion that it was a good thing (or maybe not, for those who thing that multiple inheritance is evil) that C++ compilers took care of that for us.

It''s not really an argument against C. Maybe more of an argument agains our weak programming skills. If you write C programs, you probably won''t find yourself needing multiple inheritance code, because that''s not the way you''ll have designed your program. Though you never know what your code will look like 3 years into the project.

OOP is a two-edge sword. On one hand, it gives you support for issues that often arise in programming, sweeping the implementation details under the rug, as it is - the standard C++ string class, the STL containers are prime examples of that. On the other hand, your program can get arbitrarily complex if you get obsessed with object-oriented design. Having a few classes for stuff that lends itself well to being stuffed into a class works just fine for me.

Share this post


Link to post
Share on other sites
quote:
Original post by graveyard filla
ive seen that quote. its ".. with C++, you can re-use the bullets "




The correct quote is on Bjarne Stroustrup''s homepage

quote:

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.



I don''t know who made up the re-use bullets thing, but it fits for c++ too, as c++ was designed to make reusing code a lot easier than plain c, and therefore take any possible bugs with it.

Share this post


Link to post
Share on other sites
quote:
Original post by Beer Hunter
I''m curious to know why it''s so hard to implement. Can you link me to an explanation?


Principally because the compiler ''knows'' things about the structure of the code that we don''t have access to from within the code itself without actually writing our own compiler. Without that information, you sure can''t populate your virtual function table automatically, since multiple inheritance requires you to reconcile object layouts from all parents - In C++, you have several sub-objects stored in the child object, each function pointer in the virtual function table is associated with an offset locating that sub-object, so that A''s functions act on A and B''s functions act on B. Try that piece of (C++) code out:


#include <iostream>

class A { int i; };
class B { int i; };
class C : public A, B {};

int main()
{
C object;
A* pa = &object;
B* pb = &object;

std::cout << "pa == pb ? " << (pa == pb) << std::endl;
std::cout << "pa = " << (void*)pa << std::endl;
std::cout << "pb = " << (void*)pb << std::endl;
}


Unless I made a mistake in the code above, pa and pb resolve to different addresses, but the compiler treats them as equal.

What this means is that your C framework must do a pointer fixup before calling any of the object''s member function - which you cannot modify, the parents ''classes'' do not know that they are going to be used in a multiple inheritance scheme.

Not only that, but you need to appropriately map the child''s ''member functions'' to the parent''s yourself. While you can do a fixup before the call so that the member function acts on the right subobject, you still need to provide a way to find the function itself. You placing them as data members screws polymorphism up, and placing them in a virtual function table leads to conflicts, unless you want to do fully dynamic lookups by name, as python does for all members (functions and variable).

When all is said and done, you end up crafting each ''object'' entirely by hand, which is why, as far as I can tell (I don''t have a copy of ''The Design & Evolution of C++'') "C with classes" was implemented as a preprocessor and not as a set of library routines & macros.

Share this post


Link to post
Share on other sites
I just can''t accept "it has multiple inheritance" as a valid excuse not to use C++.

Nobody *forces* you to use it. You don''t have to use classes at all if you don''t want to. If you do use classes, you are perfectly allowed to shun multiple inheritance.

In practice multiple inheritance is rarely used in C++ (by me anyway). Odd cases are clearly visible.

In most cases, you can sensibly use composition in lieu of multiple inheritance, and achieve the same thing with less ambiguity.

Mark

Share this post


Link to post
Share on other sites
C is a great language, and you''re certainly not wasting your time becoming proficient. However, C has fairly weak type-checking, so it''s pretty easy to make crashing mistakes.

Most of what I write is plain old ''C'' code, but by simply putting the code into a .cpp file, you get the benefits of C++ type-checking and a few other niceties (like function overloading) without having to worry about the oo stuff.

Share this post


Link to post
Share on other sites
Really it doesnt matter which programming language you use, they all use the same fundamentals...
(learn asm, thats when it gets fun!)

Share this post


Link to post
Share on other sites