In the past, the Numerical Recipes book was considered the gold standard reference for numerical algorithms. The earliest Fortran Edition was followed by editions in C and C++ and others, bringing it then more up-to-date. Through these, it provided reference code for the state-of-the-art algorithms of the day.

The algorithms themselves are very good for general purpose problem-solving. It is their implementations that might leave something to be desired. But that is OK because the code in the book is simple enough to modify to whatever your tastes are. The implementations in the chapters are fairly "self-contained" and free of cruft. Numerical recipes is still a good reference for times when you need to implement some basic numerical stuff but don't want/need a huge complex or expensive library or framework.
–
AngeloNov 14 '11 at 12:52

3

As it stands, this question could be considered offensive, it's certainly not very constructive. I have made use of Numerical Recipes throughout my career and would highly recommend it to anyone needing a ready reference for algorithms to solve complex problems. I have never used the code directly, but I have always implemented the algorithms in my own languages using my own preferred interfaces. The problems you appear to see are superficial, and there will usually be better algorithms out there if you care to look, but even then NR is useful to point you in the right direction.
–
Mark BoothNov 14 '11 at 13:10

4

I have to agree that the C and C++ code provided in the books proves once again that a good Fortran programmer can write good Fortran code in any language. However, these books are still a great reference. The explanations of the algorithms are very clear. The code is usable out of the box, and if it really offends your sensibilities you can always rewrite it yourself. It would still be much easier than to implement it from scratch.
–
DimaNov 14 '11 at 18:28

12

Remember that the copyright restrictions on the code in NR are quite draconian. You are only allowed to personally key in the code for up to ten routines, and your are NOT allowed to distribute the resulting program to any other person or computer. In almost any working environment this means you are going to have to re-implement the algorithm anyway, so what would be the benefit of the authors providing a sophisticated OO or functional implementation? The service provided by the book is a clear explanation of important algorithms, not the provision of a strong math library.
–
Charles E. GrantNov 14 '11 at 19:38

3

Who cares what the code is like? Wrap it up nicely and never look at it.
–
David HeffernanNov 17 '11 at 23:06

Numerical Recipes is still, IMO, a useful book. It describes the algorithms really well, including their derivation, the situations in which they're useful, and alternatives to consider when they aren't. I've been using the book for years.

One thing I have never used is their code. I always write my own implementation based on the algorithms they describe. In that respect the quality of their code doesn't matter (and it is indeed questionable: in the 2nd edition C book, they define a collection of functions and macros to make arrays unit-indexed because the authors come from a Fortran background). As an example: I once had to implement FFT in Objective-C, so I used NR in Fortran to understand what FFT did and how the code should look.

Think of NR the same way you think of Knuth: you would never paste code from that book into your project.

The code is Fortran translated to 'C' but that's OK you can just translate it back to Fortran and then into C++ yourself! There are advantages to the Fortran or C versions in that the code is pretty much self contained, you don't have to drag in a bunch of C++ classes to do matrices, complex, etc - especially given the quality of their coding!

There is a justifiable objection to the ludicrous copyright claims by the authors and I know a number of lecturers that ban NR in their classes. Among numerical experts the books also have a reputation as "enough information to get you into trouble". But their only suggestion is generally to use their personal code or buy NAG.