Hacker's Delight
Hacker's Delight is an impressive compendium of clever tricks for programmers. Warren concentrates on micro-optimizations -- few of the tricks in this book operate on more than 3 or 4 words of memory -- and he displays an impressive knowledge of diverse computer systems in the process.
Who Should Read This Book
Hacker's Delight is hardcore in its presentation and subject matter. I would not recommend this for a beginning programmer -- to fully understand the material requires at least some knowledge of concepts such as Assembly and Machine languages. However, anyone who writes performance-critical software should read this book, even if they do not plan to write Assembly code, both to learn the tricks given, and to learn the concepts behind them.
What's Good
The book is organized into chapters where Warren presents related tricks. In each chapter, he presents a few tricks which perform related tasks -- for example, in Chapter 3, he presents tricks for rounding (up or down) to the next power of 2, rounding to a multiple of a known power of 2, and detecting power-of-2 boundary crossings (i.e., checking for page faults). For each trick, he discusses why it works, whether the technique is generally applicable, related tricks which might be better in specific situations, and where a trick might be used in the real world.
Warren keeps his discussion architecture-neutral, while noting optimizations and problems for specific architectures for specific tricks -- in the process, he displays a vast array of knowledge about specific processors, from 1960's mainframes to x86, MIPS, PPC, Alpha, and others. He also skims the surface of hardware-design issues in a few places -- for example, he devotes a page or two to explaining why computers use base 2 for arithmetic, and why this is the most efficient choice.
What's Bad
This is an extremely dense book, and there are sections which are difficult to understand. Furthermore, there are many tricks which, while interesting, would be difficult to apply to real-world applications, and use of these tricks does violate the Keep It Simple, Clock Cycles Are Cheap And Someone May Have To Understand Your Code philosophy which is harped upon so heavily (not without reason) in modern software design. However, someone writing a compiler or high-performance code may feel that the benefit outweighs the potential risk.
The Summary
If you want a better understanding of the hardware on which your code runs, or you need to squeeze clock cycles, or you just enjoy seeing clever tricks, this is an excellent book. If you primarily use high-level languages such as VB, perl, python, etc., this may not be the right book for you. Be prepared for very dense material.
You can purchase Hacker's Delight from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Furthermore, there are many tricks which, while interesting, would be difficult to apply to real-world applications.
Maybe you should break open the old CS textbook instead. IMO, learning general principles would be a much better use of your time.
This is a great book for those looking to expand thier minds beyond the usual low-level-phobic computer science pulp. I do not employ any of the book's teqniques in my code, but I'm glad to know of them.
I am pleased to see the correct use of the term "hacker". Now if we could just work on the folks at CNN...
That's not to say that I don't enjoy reading about these clever things; there is a lot to be learned by studying this stuff. But implementing them is usually a mistake these days, if for no other reason than because there's already a portable way to do it which is probably more efficient. To go back to the Duff's Device example, almost all compilers will implement loop unrolling already. And that's a C-language trick, supposedly already a high-level language. Note I said supposedly! :-)
Many times the 'tricks' method is less readable, and nothing more.
A good compiler will recognize produce the same optimized byte code for different code blocks. It should unroll shorter fixed lenth loops and automatically inline function calls when it determines that it's not worth the overhead of popping the caller onto the stack.
In the end it's the design as a whole that will determine efficiency. For instance, recursion. As soon as it's learned, a coder has a tendency to use the 'cute trick' of recursion everywhere, and doesn't realize that it's rarely the optimal solution to a problem.
Personally, I loathe the 'cute-ass cryptic trick' coding philosophy. I constantly battle with all the bad habits I picked up having been born and raised on the Commodore 64. Unconditional branches (goto), cramming all the code you can onto one line, one or two letter variable names, functions longer than a chapter of the bible. Blech.
I don't need no instructions to know how to rock!!!!
aimed more at getting more features then having a fast, stable program
As I understand it, "stable" is kind of in opposition to both "fast" and "features". The reviewer's point is that super-optimized code tends to have strange tricks in it that are difficult to read and understand. That makes the code hard to maintain and increases the likelihood of bugs, so performance tweaking isn't a great idea unless speed is really important to an application.
So? Most technical books are useless for 99% of people. I personally have no use for The Black Art of C# in 21 Days For Idiots. For my part, I used to write compilers. This book would have been invaluable for me. I guess I was in the 1%.
The only danger in this kind of book is that people will use the techniques in it blindly, in which case they arguably shouldn't be writing software anyway (or at the very least should have it thorougly reviewed before committing).
So if you have to produce code like the Linux kernel, it sounds like the book for you.
Incidentally, the Linux kernel is that way for several reasons, some of which are valid (e.g. profiling or back-of-the-envelope calculations showed that something was going to be a bottleneck) and some of which made sense at the time. For an example fo the latter, see do_pipe() in fs/pipe.c. If starting the kernel again today, it would make a lot more sense to use C++ which would make all those gotos unnecessary, but it's a bit late now.
sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});