[NBLUG/talk] If you love him/it so much, then defend him/it.

Andru Luvisi luvisi at andru.sonoma.edu
Sun May 25 07:03:01 PDT 2003


On Fri, 23 May 2003, Steve Zimmerman wrote:
[snip]
> Does Donald E. Knuth ever simplify anything?
>
> Does C++ ever simplify anything?
>
> Burdens of proof's on you.  From what I've seen,
> Knuth starts complex, stays complex and ends
> complex, and C++ is always getter *more* complex.

Knuth's goal is not to be simple.  It is to be complete.  As I was told
years ago, if you want to be a code monkey, read one of those "Learn Foo
in 21 Days".  If you want to be a computer scientist, read Knuth.

Many text books only explain what you should do in order to achieve a
certain result.  Knuth explains how it works, why you should do it a
certain way (or avoid another way).  Rather than just giving you a good
generic answer like most text book authors do, he gives you many
techniques and explains the relative merits of each so that you can choose
the one that is best suited for the application you are working on.  If
you want to eek out every last bit of performance, he will show you how to
analyze and optimize the running time of an algorithm.  If you don't, you
can skip all the math and read the summary of his performance analysis to
pick an algorithm that should be good enough for you.

Knuth is also more of a scholar than many authors.  For a given technique,
he gives its motivation, its history, credit to its pioneers, references
to seminal articles and books, and so on.

Knuth's books are not for the beginner.  The introduction says as much.
However, his books make it a lot easier to go from "can program" to "good
at programming".

As for C++, it too never had simplicity as a goal.  I too found C++
hopelessly complicated until I got around to reading "The C++ Programming
Language" by Bjarne Stroustrup.  As I understand it, the goal of C++ was
to allow a programmer to write code that is as fast as C code, yet still
use some of the more recently developed techniques such as object oriented
programing and polymorphic functions.  If you don't care about speed and
just want to have more powerful development tools available to you, there
is always Lisp, Perl, Python, Smalltalk, and so on.  If you only care
about speed and don't need things like inheritance and polymorphism, there
is always C, FORTRAN, and such.

C++ is for the programmer who needs to write a complicated program, such
as a simulation, which object oriented abstractions make easier to write,
and who also needs it to be as fast as possible.  Its object oriented
features only go as far as they can without sacrificing performance, which
means that C++'s object oriented capabilities are not as complete as those
of some other languages.  These limitations can be frustrating at times.
It is a language of compromises.  It does neither task (speed,
abstraction) as well as many other languages, but it is also better than
most languages at one of those tasks.  That is, most languages that are
better at abstraction than C++ are slower, and most languages that are
faster than C++ are not as good at abstraction.

This may sound strange given C++'s reputation for slowness.  I believe
that this reputation comes from people using C++ who do not fully
understand C++.  As Dennis Ritchie (one of the inventors of C and UNIX)
once said, UNIX has to let you do stupid things in order to let you do
clever things.  I believe that the same goes for C and C++.  It is easy to
write code that (to borrow a line from one of the Perl books) makes
continental drift seem fast if you do not understand what is going on
under the hood.  For example, using call by value inside of a frequently
executed bit of code, with large data structures that have expensive
initialization, will bring the fastest computer to its knees.  In C this
is not possible, so people don't do it.  In C++ is is easy to do this by
mistake.

To put it another way, in gaining some of the power of Lisp, C++ also
gained some of the pitfalls of Lisp, such as the ability to easily write
slow code if you are careless.

As the old saying goes, use the right tool for the right job.  If C++ is
not the right tool for the job you are doing, then you probably will not
be happy with it.  If it is, then you probably will be happy with it.

Andru
-- 
Andru Luvisi, Programmer/Analyst

Quote Of The Moment:
  "In order to make an apple pie from scratch, you must first create the
  universe."
                  -- Carl Sagan




More information about the talk mailing list