Why C++ is vastly superior to C

C

crea

Lynn McGuire said:
Why C++ is vastly superior to C:
http://warp.povusers.org/programming/cplusplus_superior_to_c.html

"In conclusion, the reason why C is so vastly inferior to C++ as
described in this article can be summarized with one single sentence:
C has no support for RAII nor templates, while C++ does. That's two
of the most important features that make C++ by far the superior
language."

the main thing is the object oriented approach, i guess. Also many improved
version of functions
 
B

Balog Pal

Lynn McGuire said:
Why C++ is vastly superior to C:
http://warp.povusers.org/programming/cplusplus_superior_to_c.html

"In conclusion, the reason why C is so vastly inferior to C++ as
described in this article can be summarized with one single sentence:
C has no support for RAII nor templates, while C++ does. That's two
of the most important features that make C++ by far the superior
language."

Quite so. Another "most important" feature was parting with "locals at block
start", but it got into C99 in the mantime. (too bad that real-world C is
still at C90, a decade+ after the last revision, and massive projects still
stick to that old known bug generator. :( )
 
K

Krice

"In conclusion, the reason why C is so vastly inferior to C++ as
described in this article can be summarized with one single sentence:
C has no support for RAII nor templates, while C++ does. That's two
of the most important features

You can live without templates, it's the least important feature
of C++ and people constantly over/misuse it. Most important feature
is class programming: instances, encapsulation and inheritance,
the OOP basics.
 
J

Juha Nieminen

Krice said:
You can live without templates, it's the least important feature
of C++ and people constantly over/misuse it. Most important feature
is class programming: instances, encapsulation and inheritance,
the OOP basics.

I disagree.

Encapsulation and instantiation are extremely important, yes, but you
can achieve that to a certain degree in C as well. Access rights might
not be enforced by the language (except on the compilation unit level),
but you can achieve this to a certain degree by agreement (iow. "don't
touch anything inside this struct"). Yes, this is not perfect, but it's
not catastrophical either. This is not the main reason why C is inferior
to C++.

Inheritance is useful in some situations, but it's far less useful than
was thought at the height of the OOP craze in the 90's. It definitely has
its uses, but it has its shortcomings as well. It is an important feature,
but I would certainly not rank it higher than RAII and templates.

As for templates, I fully disagree: A C++ without templates would be
almost as horrible as C is. (RAII would still make it by far superior,
but the lack of templates would be a huge setback nevertheless.)

If you can live without templates, how would you implement the last
challenge in the article (iow. making the example Matrix class generic,
to support any numerical type, including those which do not behave like
basic types)?

On the same note, how would you make generic data containers and
algorithms which are as efficient as possible? (Note their prominent
absence in standard C; there's a reason for that.) Other programming
languages manage by other means, but they often suffer from poorer
efficiency (especially in the memory consumption department, sometimes
also in the speed one).
 
L

Lynn McGuire

You can live without templates, it's the least important feature
of C++ and people constantly over/misuse it. Most important feature
is class programming: instances, encapsulation and inheritance,
the OOP basics.

I could not live without the Standard Template Library.

Lynn
 
Ö

Öö Tiib

I disagree; generic programming is just as important as object oriented
programming.

+1.

Encapsulation can be done well in C. Just like the FILE* in C library.
You know nothing about it but the functions ("methods") with what you
can manipulate one. Similarly abstract interfaces and polymorphism can
be implemented in C with function pointers. There is some semantic
overhead but that can be reduced with macros. It is easy to write
small quick programs in pure C.

C++ however scales well. Templates in interface simplify integration
of your code with a library by huge margin. The big legacy C++
libraries have gradually increased presence of templates in their
interface. In boost and in Loki the templates are sometimes overused
but that is because the authors were curious and like to explore the
possibilities.

RAII is great way to reduce the need for garbage collection. Being
careful you create no garbage. The usual garbage collection takes care
of least important resource ... the memory. I have started to hate
Windows lately because some of the garbage collected crap has left
files open and so i can't delete those without closing all the
applications. Also the applications start back up slowly like snails.
 
N

Nobody

You can live without templates, it's the least important feature
of C++ and people constantly over/misuse it. Most important feature
is class programming: instances, encapsulation and inheritance,
the OOP basics.

Maybe for you. OTOH, if performance matters, templates are essential.
And if performance doesn't matter, higher-level languages offer the OOP
features with less hassle. IOW, if you don't need templates, you probably
don't need C++ either.
 
K

Krice

I could not live without the Standard Template Library.

Mostly because core C++ doesn't have something like std::string
or vector. If I need to write a template (beside using STL)
I know there is something wrong with the class hierarchy. It's
like using cast, you know it's a workaround to a design error.
 
J

Joshua Maurice

Maybe for you. OTOH, if performance matters, templates are essential.

I want to emphasize this. Templates are nice for code reuse, but
several posters ignored IMHO the most important aspect of their
utility. Templates allow generic code and code reuse without runtime
overhead. For too many people, and for some people with legitimate
concerns, there is almost a knee-jerk fear of runtime overhead, and
thus they would rather roll their own, every time, instead of use a
standard library or well tested, well optimized, library solution,
because of the overhead that using a non-template library would
impose.

Take C's sort. The comparator function is a function pointer, and the
last I heard is that most compilers simply will not expand that
inline, as opposed to C++ various sort functions which can be expanded
inline.
 
B

Balog Pal

Krice said:
Mostly because core C++ doesn't have something like std::string
or vector.

String could very well be a simple class, but how do you create a good
vector without templates? Do you suggest to go back to only have the
"Object-based" polymorphic array? Even java failed miserably on that point,
if you recall the hype raving that templates are not good and would never
make it into a cool language of theirs. Finally generics were incorporated
around 1.5 -- mainly to cover the mass problems with collections. :)
If I need to write a template (beside using STL)
I know there is something wrong with the class hierarchy.

The most ubiquitous problem with class hierarchy is thet you don't need one
in the first place.
Sure, having hierarchy is great for some particular cases, I both used and
wrote such, but it is in minority by far.
It's like using cast, you know it's a workaround to a design error.

I don't see any likeness. Hierarchy is good for runtime polymorphism, while
templates cover the common case where the type is fixed at compile time.
 
E

Ebenezer

  I'm glad I'm not writing those articles just for myself... :)

Also from the conclusion:
"The example I described in this lengthy article is but just one of
the reasons why C is so vastly inferior to C++."

The "but just one" part is not common usage. You could
use "but one of ..." or "just one of ..." I think the latter
would be good. I think I'd cut the vastly word also -- "so
inferior" pretty much covers it.
 
R

Rui Maciel

Krice said:
Mostly because core C++ doesn't have something like std::string
or vector.

Why would anyone extend the base language to incorporate something which
is easily implemented (and, better yet, extendable) through other basic
language constructs?

If I need to write a template (beside using STL)
I know there is something wrong with the class hierarchy.

Do you know how I can tell you aren't a good programmer?


Rui Maciel
 
R

Rui Maciel

Balog said:
Quite so. Another "most important" feature was parting with "locals at
block start", but it got into C99 in the mantime. (too bad that
real-world C is still at C90, a decade+ after the last revision, and
massive projects still stick to that old known bug generator. :( )

What do you mean by "real-world C is still at C90"?


Rui Maciel
 
I

Ian Collins

What do you mean by "real-world C is still at C90"?

C99 compilers are by no means universal. A lot of embedded (the
majority of C projects) projects are still stuck with C90 tools.
 
J

Juha Nieminen

Krice said:
If I need to write a template (beside using STL)
I know there is something wrong with the class hierarchy. It's
like using cast, you know it's a workaround to a design error.

What happens when the STL is not enough? There are myriads of different
data containers out there, and the STL only offers about 5 of them.

Why is it a design error to make your libraries generic and reusable?
That sounds to me like the exact opposite.
 
I

Ian Collins

Why C++ is vastly superior to C:
http://warp.povusers.org/programming/cplusplus_superior_to_c.html

"In conclusion, the reason why C is so vastly inferior to C++ as
described in this article can be summarized with one single sentence:
C has no support for RAII nor templates, while C++ does. That's two
of the most important features that make C++ by far the superior
language."

I normally just use RAII as the reason. Everything else else can be
kludged in C, but not RAII.
 
K

Krice

Do you know how I can tell you aren't a good programmer?

I'm the first person in the world who wrote a roguelike with zero
bugs.
A thing like that didn't even exist before I made that possible.
I'm not good, I'm the best.
 
J

Juha Nieminen

Ian Collins said:
I normally just use RAII as the reason. Everything else else can be
kludged in C, but not RAII.

It's quite difficult to kludge any kind of generic data containers in C
(which is probably the reason why the standard C library does not offer
any such containers). You could achieve something similar with preprocessor
macros, but it would be quite limited, and definitely less safe (in big
part because of the lack of RAII, constructors, destructors, etc).

You could perhaps make some more or less generic containers for basic
types and structs which only contain basic types (but not pointers) with
preprocessor macros, but immediately when you need more resource management
than that (such as a struct that as pointers pointing to dynamically
allocated memory or other such resources) it becomes complicated. For that
same reason it's complicated to make the containers nested. (Assigning
a container object would not be the same as assigning a basic type.)

It's so much simpler with C++ templates. Just write any amount of
nested containers you want, no problem.

std::deque<std::list<std::vector<std::set<std::string> > > > container;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top