[Israel.pm] Your "when C is the best tool" article
shlomif at iglu.org.il
Mon Apr 9 04:52:01 PDT 2007
Hi Aur! (and all)
On Monday 09 April 2007, SonOfLilit wrote:
> Hi Shlomi,
> This is Aur (from Israel.rb).
Israel.rb == Ruby-IL.
> I've read your "When C is the best tool for the job" article.
Just for the record it is here:
> My impression is that after promising to deal with the list of claims:
> (1) * "Java and/or .NET are better than C in every way.".
> (2) * "Perl/Python/PHP/Ruby/Tcl are better than C."
> (3) * "LISP is better than C".
> (4) * "If you need speed, use O'Caml or Haskell - don't bother with C."
> (5) * "C is for kernels."
> , you only deal with (1), (2), (5).
Actually, these and many similar claims are encountered times and again on the
Net. I tried to address the common theme.
> By giving an example of data crunching code that benefits from speed,
> you rule out Java and scripting languages.
I gave up Freecell Solver as an example, but it may not have been the best
example. I also regret the fact that:
I explained why the Freecell Solver code will be slower in Java, but not why
it will also *feel wrong* in Java.
( http://www.shlomifish.org/philosophy/computers/when-c-is-best/ )
I should also note that OSNews have done me a dis-service by linking to the
raw HTML page of the article itself instead of the cover page, because the
cover page contains a vital correction and some links. I've learned from this
mistake and now try to make sure my articles are part of the site flow.
> You don't rule out high level compiled languages. You say nothing at
> all about how would the code be written in them.
> Why not write this code in Haskell? OCaml? APL? Lisp?
1. They often tend to have implementation problems. C just works, and gcc
works extremely well. Almost everything of importance nowadays is C or
C-hosted. Compare it with ghc (the standard Haskell compiler) that requires a
recent enough version of itself to compile.
2. They are often not as straightforward to program in than C. I know that
when I tried to implement an algorithm using Haskell with an array map for
Primes (a variation of Arthostenes' Sieve) it didn't work alright and did not
scale, while in Perl and C - it ran perfectly fine. (I suppose O'Caml would
A hash also doesn't work quite right in Haskell. The two prominent projects I
know that are written in Haskell: darcs and pugs are both very slow, and
consume a lot of memory. Moreover, it takes a long time to compile pugs. You
may think it doesn't matter, but people like things to compile quickly so
they can develop faster, not be distracted to do something else for a long
time, and get over with it quickly. This is also an argument against funky
C++ code (like KDE's) using g++.
3. They tend to consume much more memory than C. I once thought O'Caml could
be a good substitute for Forth for satellites until I discovered that some
types of satellites can use only 128 KB of memory.
4. They're still an abstraction and an abstraction is not always what you
want. Sometimes you want to be close to the machine.
5. They tend to be much more buggy than gcc.
6. Some UNIXisms (or Win32isms) in them are harder to do in them, or otherwise
fell non-native than in C.
7. If you want to implement a virtual machine, then C is your best bet. perl5,
python, php, ruby, io, lua, clisp, most Scheme implementations, java, Mono
and Microsoft .NET, etc. are all written in C. To say nothing of C compilers.
8. You obviously cannot use Lisp or O'Caml for kernel code. However, one
should note that the amount of things you can do in user-land is growing. On
Linux (and other systems) nowadays, file systems, USB drivers, protocol
implementations, serial or parallel port controllers, etc. in high-level
languages, including Perl and friends.
However, some things are still too-level, too real-time or need to be too-fast
This is just off the top of my head.
I'm not saying you can't use higher-level languages than C for many domains
where once C or before that Assembly dominated the market. However, some
things still require C.
Some criticisms of the article said that similar opinions were voiced when C
started to become popular and people wrote things that said it won't
completely displace Assembly. Well, while C has become more popular than
Assembly, there's still a lot of code written in Assembly nowadays. So I
believe higher-level languages won't completely displace C either.
Shlomi Fish shlomif at iglu.org.il
If it's not in my E-mail it doesn't happen. And if my E-mail is saying
one thing, and everything else says something else - E-mail will conquer.
-- An Israeli Linuxer
More information about the Perl