Hello,
On Thu, 01 Oct 2009, Prem Kurian Philip wrote:
> From: Rahul Sundaram <[email protected]>
>
> >Never say never. There has been quite a few demonstrations otherwise
> >available on the web. Feel free to look them up.
>
> Again, it comes down to the algorithm used. If the algorithm used in C is
> poor, then it is likely to be slower than the same functionality
> implemented in a higher level language using a better algorithm.
Please do follow Rahul's suggestion and look it up!
Take the following program in LISP:
(def fact (n) (fact1 n 1))
(def fact1 (n k) (cond
((leq n 1) k)
(t (fact1 (sub 1 n) (times n k)))))
Let us translate this program/algorithm literally in C as:
fact1(int n, int k) {
if (n <= 1)
return k;
else
return fact1(--n,n*k);
}
fact(int n) { return fact1(n,1); }
It is quite likely[*] that the (compiled) LISP program will execute
faster and use less stack space than the C program. This is because
LISP compilers typically implement "tail recursion optimisation"
whereas C cannot (since C allows "side-effects").
> Since C is just a very thin abstraction over assembly language, it will
> tend to be quicker than pretty much anything else out there. Which also
> explains why the Linux kernel is implemented in it. The only thing quicker
> would be to get the compiler to output the code in assembly language and
> then hand optimize the code before running it through an assembler.
These "operating system related" things is what C is optimal
for. There are a _lot_ of different uses for computers and for many of
them C is _not_ optimal --- even in the sense of efficiency.
Indeed, all Turing complete languages _can_ implement each other's
features through translation. However, such translations typically
involve a small per-instruction cost which becomes significant cost
when a big project is implemented. Thus, each language has its own
"domain of expertise".
A thought for this thread:
"A carpenter who only uses a swiss-army knife would be a poor
carpenter, so why do some programmers insist on using only one
language?"
Regards,
Kapil.
[*] I have qualified my claim about this particular program since it
is not large enough for differences to really show up.
--
_______________________________________________
To unsubscribe, email [email protected] with
"unsubscribe <password> <address>"
in the subject or body of the message.
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc