The best kittens, technology, and video games blog in the world.

Wednesday, November 07, 2012

Think Like a Programmer by Anton Spraul - book review

In The Night All Cats Are.. Err.. Gray? by meantux from flickr (CC-NC)

The book "Think Like a Programmer" tries to teach people relatively new to programming how to approach problems and program solutions.

The idea is good, but the book has one massive flaw - it uses C++. I'm not going to kick the dead horse and repeat all reasons why C++ is horrible in general - but it's especially horrible for teaching problem solving to beginners.

Irrelevant low level details caused by limitations of C++ keep getting mixed with solutions of discussed problems throughout the book. Many problems like constant sized arrays, pointer lifetime management and so on, lack of usable containers, I/O, and string functions in standard library and so on simple don't exist in civilized language.

And sadly such basic ideas as:
  • experiment with your problem in REPL
  • start with writing unit tests for your problem
  • check if standard library can solve part of your problems
  • check if any easily installable third party library (via CPAN, rubygems, or whatnot) can solve part of your problem
are completely alien to C++ thinking.

Other than this one huge flaw the book is really nice. All code is very nicely formatted with inline bullet point references and shading for commentary, all problems are explained with liberal use of relevant diagrams, methodology of breaking problems into steps and solving them separately is executed quite well, and even various pain points of C++ tend to be handled as reasonably as they can.

Other than choice of C++, the only other problem is that while problems tend to be broken into small steps to be solved one by one, solutions to these small steps are then typically put together into one big lump of code instead of being left alone as separate functions or methods, and this code tends to be much more complex than it should be. I blame C++ for that as well.

I urge the author to write a Python or Ruby version - or at least Java version for that matter. Using C++ in a book for beginners mostly just shows the basic problem solving mistake - not choosing the right tool for the job, and it really distracts from what the book is supposedly trying to do.


If you're a beginner to programming and your school or university forces you to learn C++ in 2012 this book might be really useful to you. Also find a lawyer and sue your school for emotional trauma caused by C++.

If nobody makes you learn C++, I'd skip it. It's very C++-centric, and many of its lessons are not directly applicable to more sensible languages.

If you know a bit about programming from point of view of a high level languages, and are trying to learn C++ now, it might actually be reasonable supplement to C++ textbook.

If you're coming from reasonable C to C++ world, you probably won't find much of it useful. You'll presumably know most of it already, and advanced C++ issues like boost libraries won't be even mentioned here.

And in interest of full disclosure, I got this book as a free review copy.

No comments: