C or C++ ?
I have always used C but everyone seems to love C++. Why? It is easier to work with classes (or so i''m told) but it is not nessicary to use them. C is very fast and effecient and it just seems to me like C++ is just C with a bunch of weight added. infact, sometimes i use them interchangably without noticeing any difference. I have always preferred C for its speed and simplicity. What say ye?
- Twisted Matrix
- Twisted Matrix
Why would c++ be any less fast or efficient than c?
Also...
This isn''t so bad. But what would it look like if it were written in c?
Also...
#include <algorithm>#include <iostream>#include <map>#include <string>using namespace std;struct WriteStuff { void operator()(const pair<string, int>& data) { cout << data.first << ": " data.second << endl; }};int main(){ map<string, int> count; // type an eof character (ctrl-z under windows) when done string word; while (cin >> word) ++count[word]; for_each(count.begin(), count.end(), WriteStuff()); // cin.clear(); // cin.get(); // uncomment these if you''re running from an IDE}
C++ allows better organization through OOP, which when used properly will run every bit as fast as comparable non-OOP C code. The features of OOP, such as polymorphism and inheritance give you a vast amount of power, by their very definition.
NOTE: This post, while factually based, expresses an opinion. In the end, the language wars will remain unresolved because it comes down to personal preference. Use what works.
Peace,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
NOTE: This post, while factually based, expresses an opinion. In the end, the language wars will remain unresolved because it comes down to personal preference. Use what works.
Peace,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[twitter]warrenm[/twitter]
Language features you''re not using do not affect the performance of your code.
Language features you''re using are most likely more efficient and safer than their equivalent C implementation - assuming you''re using them correctly, and not just because they''re there.
- The C++ compiler developpers knew their complete specification and could implement them optimally, while you''re at the mercy of the C compiler''s optimisation of what it sees as ''ordinary'' code. Which gets even worse if you want to make the ''feature'' easily usable, often leading to internally obfuscated code that the compiler will have a hard time optimising.
- C++ language features are safer than their C equivalent. If anything, C++ has stricter typechecking. Templates can be mimicked in a very limited way with macros (though the preprocessor has no knowledge of types, so you can''t have type indirections - no policy classes) - note that templates are a compile-time feature : they add absolutely no weight by themselve. std::sort() beats the crap out of qsort() any day.
Of course, you have to learn the language features - C++ is a bigger language than C. If that''s what''s stopping you, too bad for you. If not, it can be very helpful to try to understand them in terms of their C implementation (q.v. "Inside the C++ object model" by S. Lippman).
It''s not a question of object-oriented versus procedural (you can write OO code in C, the ''seams'' will just be apparent) : the more languages you know, the better your understanding of any of them is. Studying languages like Prolog, Lisp and Haskell is positively enlightening.
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
Language features you''re using are most likely more efficient and safer than their equivalent C implementation - assuming you''re using them correctly, and not just because they''re there.
- The C++ compiler developpers knew their complete specification and could implement them optimally, while you''re at the mercy of the C compiler''s optimisation of what it sees as ''ordinary'' code. Which gets even worse if you want to make the ''feature'' easily usable, often leading to internally obfuscated code that the compiler will have a hard time optimising.
- C++ language features are safer than their C equivalent. If anything, C++ has stricter typechecking. Templates can be mimicked in a very limited way with macros (though the preprocessor has no knowledge of types, so you can''t have type indirections - no policy classes) - note that templates are a compile-time feature : they add absolutely no weight by themselve. std::sort() beats the crap out of qsort() any day.
Of course, you have to learn the language features - C++ is a bigger language than C. If that''s what''s stopping you, too bad for you. If not, it can be very helpful to try to understand them in terms of their C implementation (q.v. "Inside the C++ object model" by S. Lippman).
It''s not a question of object-oriented versus procedural (you can write OO code in C, the ''seams'' will just be apparent) : the more languages you know, the better your understanding of any of them is. Studying languages like Prolog, Lisp and Haskell is positively enlightening.
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"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
My unprofessional opinion:
Learn how to use OOP, then forget that there''s even a difference between C and C++. Use classes when a class is called for and other than that, break out the structs and class-less functions.
"You TK''ed my chicken!"
Learn how to use OOP, then forget that there''s even a difference between C and C++. Use classes when a class is called for and other than that, break out the structs and class-less functions.
"You TK''ed my chicken!"
quote: Original post by TwistedMatrix
I have always used C but everyone seems to love C++. Why?
Lots of reasons, some good some bad. Probably the overriding reason is that C++ offers a greater freedom of expression than does C, since it has a greater range of language constructs. That means you have more scope for choosing the right construct for the situation.
For many people, such freedom of expression is problematic and leads to them creating large piles of crap. It's a bit like a drunk winning the lottery - give a reprobate the means to do as they please and the result will not be pretty. IME, the most common reasons for such a result is that the developer is unable to reason about what is the best construct for the situation (often through ignorance) or unable to abstract. The latter is a *big* problem in software - ignorance is curable, but inability to abstract seems to have an element of "either you've got it or you haven't" and not many people have it. Having said that, I'm fairly convinced people *can* learn to abstract, but it's not well understood who can learn to do so and how they can go about it.
This inability of great masses of people to abstract problems has helped create the impetus behind phenomenons such as Design Patterns. For such developers, the freedom to create huge piles of crap is present in any programming language, but seems to vary depending upon the multiplicities present in the language. The flip-side of this, and the possible reason for C++'s popularity, is that greater expressivity in a programming language enables intelligent developers to create superior solutions, and everyone likes to imagine they are intelligent. And lastly, a word of warning: be wary of popularity. Popularity so often means mediocrity.
quote:
C is very fast and effecient and it just seems to me like C++ is just C with a bunch of weight added.
Change "weight" for "ways of expressing ideas" and you'll be closer the mark.
quote:
infact, sometimes i use them interchangably without noticeing any difference.
Then you haven't learned the difference.
quote:
I have always preferred C for its speed and simplicity. What say ye?
You have to realise that most software is complex, and that complexity has to exist somewhere. If it doesn't exist in the language, then it probably exists in your solutions. I prefer to keep complexity at arm's length.
[edited by - SabreMan on November 12, 2002 6:00:59 AM]
I think it is easier to work with classes, but only when you start writing it. I just love the way classes work. However, as projects grow larger, it becomes more complicated. Fortunately, less complicated than using C.
SabreMan is right, it''s about "ways of expressing ideas." Isn''t that what programming is?
My compiler generates one error message: "does not compile."
SabreMan is right, it''s about "ways of expressing ideas." Isn''t that what programming is?
My compiler generates one error message: "does not compile."
The great thing is, you don''t have to pick. That''s the power of C++, you can mix and match OOP and procedural however you want. C++ has everything C has and more, you don''t have to use any of the extra features if you don''t want to.
You don't need to vote for the "lesser of two evils"! Learn about Instant Runoff Voting, the simple cure for a broken democracy!
quote: Original post by SabreMan
For many people, such freedom of expression is problematic and leads to them creating large piles of crap. It's a bit like a drunk winning the lottery - give a reprobate the means to do as they please and the result will not be pretty.[edited by - SabreMan on November 12, 2002 6:00:59 AM]
Haha! Love that analogy!!!
[edited by - Matt Calabrese on November 13, 2002 2:19:56 AM]
November 13, 2002 10:16 AM
Why ask? When this question is asked almost everyday. How about this, have a look for yourself, and then decide.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement