Previous | Gate | Korean
The reasons why I don't use C++ as my major language for software developments
Usually I use C as the major language for software developments and three
reasons are introduced here. I've studied several computer programming
languages and I think that a specific language isn't superior to the
others but it's just a tool to accomplish any desired goals.
In 1992, I'd studied FORTRAN 77 at the first time. The 2nd was C,
the 3rd was C++ and several languages including Pascal, Basic, Java, Perl,
Python, etc. have been studied. Anyway the issue in this article is focused
on C and C++ because there was a time I considered which of the two languages
can make software libraries I planned to implement can be completed more
desirably.
In 1994 I'd been fascinated with the power of C++ language and
its philosophy, so I'd made effort to conform my software developments to
the C++ world. It's right that I was a fanatic of C++ language at one time.
And in 1996, after graduating college, I began to write a data structure library
that has the linked list as the major feature because half-edge solid model
structure uses it very frequently. ( Refer to
IMA project history )
At that time I was concerned in writing small, fast, and generalized codes so
I considered how can I implement the linked list which can satisfy those
conditions. For generalization, C++ template is a good choice but I
didn't want to connive the fact that template can generalize an
implementation in the source level. For example, a template method,
template<class T> T add( T a, T b )
{
return a + b;
}
If it is called for 'int' and 'double' classes, two 'add' methods will be
generated in the final binary code. If the template codes or
classes supplied for template arguments are increased ?
So I intended to find a way to generalize the linked list implementation
in the binary level and the linked list implementation technique
used in the Linux kernel is adopted.
This technique can be applied to binary tree families, B-trees
or many other data structures and many binary codes can be reduced compared
to the implementation using template.
( This concept is applied to linked lists and binary trees in
Coral Library )
But is it impossible to use this technique in C++ language ? No, but it is
not suitable for the C++ philosophy. So in C++ world, for data structures,
STL which is implemented using template is popular.
The second reason is that the following technique which is called FAM,
Flexible Array Member in C99 standard, cannot be implemented using C++
standard allocator, 'new'.
struct _fam {
int my_code;
char my_name[];
};
struct _fam* fam = (struct _fam*)
malloc( (sizeof(struct _fam)+1) + strlen(name) );
Without C99 or compiler extension,
struct _fam {
int my_code;
char my_name[1];
};
struct _fam* fam = (struct _fam*)
malloc( sizeof(struct _fam) + strlen(name) );
Finally I want to indicate that C is the most easiest way to supply language
neutral interfaces. Name mangling and object oriented features prevent
another languages from directly calling C++ methods. CORBA or COM
use IDL, and they can be implemented using C++, but essentially they are
not C++ interfaces. And they requires more complex implementation steps.
All currently existing languages which can use CORBA or COM can use
C functions and furthermore some languages which doesn't have structure
( required for CORBA or COM ) like FORTRAN 77 can call C functions easily.
The most typical example is FGL, OpenGL for FORTRAN.
Because C is a subset of C++ so all features in C are included in C++,
but if you use a language, you should follow its philosophy.
If you write FORTRAN style C program, just use FORTRAN.
If you write C style C++ program, just use C.
I don't want to say more reasons because such opinions can be
related to personal tendency and it can cause arguments.
Anyway I don't think C++ is a bad language.
C++ has many great features, many peoples and I like it. I use C++
to capsulize API functions implemented in C or some programs already
implemented in C++.
Template is very nice feature in C++ and I miss it in C but it is
possible to write some codes similar to template using '#define' and
'#include'. :-)
2006.02.24 Last modified
2006.01.28 Started
Previous | Gate | Korean