Thursday, May 29, 2014

There is no such thing as C/C++

C/C++. Although this term is frequently used, it's incorrect and is often a source of confusion for newcomers.

Here are some major differences between the two languages:

C C++ (>=11)
#define const X
malloc, calloc, free new/delete
Raw pointers RAII and smart pointers
Procedural Procedural, modular, object-oriented and generic
Return large resources by pointers Return large resources by value (rely on RVO and move semantics)
Raw array std::vector, array
char* strings std::string
stdio.h iostream
void* templates
setjmp/longjmp/goto Exceptions
. . . . . .


One can write C in almost every language. You can write C in Java by only using static methods (equivalent of functions) and beans (dumb objects with no behavior, equivalent of struct).  However, that's far from ideal.

If a software engineer wants to be good at a certain programming language, he should first strive to learn the idiomatic way of doing things in that language. Individual features should be a secondary concern.

Considering how different the idiomatic way of doing things in each language is, the term C/C++ is not appropriate and learning C before C++ is not recommended.

No comments:

Post a Comment