[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Why is C so popular?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 27 Aug 2003, Alex Malinovich wrote:

> The recent COBOL discussion has gotten me to thinking. Some languages
> seem to be very popular in some situations. C is easily the dominant
> language for most things Linux. So therein lies the question. Why,
> exactly, is C so popular? Especially in comparison to C++. I can't think
> of a single reason to use C instead of C++ for most of the coding that I
> would do. I generally only write user applications. I don't get anywhere
> near the kernel which is where I'd imagine most of the reason for using
> C comes in. Yet I see people writing 'modern' GUI applications and using
> C when I would think C++ would be a much better choice. Is there
> something that I'm missing? Something that C actually does better than
> C++ in regards to higher-level functions?

I can think of a few reasons myself:
1) Compatibility
2) Speed
3) Portability

1) Libraries are a good thing to be written in C unless they are
specifically releated to a programming language that is not C like the
standard C++ libraries.  It is very easy to write a wrapper for a library
written in C for use in other languages like Perl, Python, C++, Java,
Ruby.  But much harder to write a wrapper for a C++ library to use in
other languages like C, etc.  The Arts client libraries are a good example
of that situation.  The libraries are written in C++ with a special
library that acts as a C wrapper.  The problem is the wrapper library is
severly limited compared to the C++ libraries, my guess is the programmers
got a little lazy when it came time to write the wrapper and it has caused
me some trouble trying to use the libraries.

Also, any C library can be used in C++ without a wrapper, but a wrapper is
required for the other direction.

And have you ever tried to open a C++ library using dlopen()?  It requires
at least one C function to start with since all the C++ functions names
are mangles.  It's doable, but a little bit of a pain.

Lastly, C has more libraries for a user programs then any other language
except C++ of course.

2) C is just faster than C++ and much faster then almost any other choice
as far as code speed.  Even when I'm writing in C++ I will use fopen() and
fprint() for file I/O then the C++ equilelants because they are noticably
faster.  C++ with never make it into the kernel for this reason along with
others.

3) C is more portable then C++.  I can take almost any C code and use it
with almost any C or C++ compiler or even other variations like Objective
C or Dynamic C with very few problems.  Most exceptions are maybe use of
newer features of C like ## or enum or directives like #pragma.  In some
enviorments C is the only way to go, other languages like Cobol, C++, or
Perl are just too high level.  Once case is the TI-89, it's to limited to
run C++ effectively.  I've never seen anyone even attempt to write a C++
compiler for it.  Other embedded systems like Microchip's PIC
microcontrollers are just barely leaving asm for C now, it will be a while
before they will support C++.  Rabbit Semiconductor sells a Z80 based
microchips and they created a language called Dynamic C which is basicly C
with special support for state machines.  It won't do C++ either.



If people don't learn C before C++, it A) a little harder to learn
properly, and B) it's harder for them to learn other languages later like
C, Objective C, and Dynamic C with are all C dirivatives.


I think this is at least a little sample of why C is better sometimes than
C++.

>
> (Note that I tend to gravitate towards higher level languages by nature.
> I use Perl religiously, and I love Java. If not for some of the speed
> limitations and, more importantly, the fact that it's non-free, I would
> say that Java is the perfect language. Hmm... is that gasoline I smell?
> :)
>
>

- -- 
I sense much NT in you.
NT leads to Bluescreen.
Bluescreen leads to downtime.
Downtime leads to suffering.
NT is the path to the darkside.
Powerful Unix is.

Public Key: ftp://ftp.tallye.com/pub/lorenl_pubkey.asc
Fingerprint: B3B9 D669 69C9 09EC 1BCD  835A FAF3 7A46 E4A3 280C

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/TFXH+vN6RuSjKAwRAqtwAJ9BgmxVuO7UZvwdMofzsYTq4guIkACcD9jI
c+DW3CWqzTO24OjznYWYeyM=
=2ghl
-----END PGP SIGNATURE-----



Reply to: