How to Think Like a Programmer
Why do programmers sometimes struggle to write programs? What’s getting in the way isn’t likely the programmer’s grasp of language semantics. V. Anton Spraul has been teaching programming for over 15 years. In his new book, Think Like a Programmer, Spraul says the problem is more likely that the missing skill is problem-solving -- that is, “the ability to take a given problem description and write an original program to solve it.”
Of course, the author admits that not every program requires extensive problem-solving, but when it does, it could stymie a programmer. After all, problem-solving “is a different activity from learning programming syntax and therefore uses a different set of ‘mental muscles.’”
To help you firm up those muscles, the author investigates several approaches to solve problems -- from a divide-and-conquer technique to reducing the scope of the problem (by adding or removing constraints). He explains that programmers can look for analogies or use experimentation and observation to figure out a solution.
Spraul begins his exploration by looking at common puzzles and, using examples in C++, explores problems including message decoding, checksum validation, and breaking string input into an integer value. (Some familiarity with C++ is useful, but it’s not into you get to the section on pointers where you really need a good grasp of the language.)
He covers a variety of common programming constructs: besides pointers, Spraul examines arrays, loops, string manipulation, classes, dynamic allocation and deallocation, list management, dynamic memory, recursion, and binary trees. The author spends chapter 7 talking about solving problems with code reuse, a never-ending goal.
In chapter 8, Spraul pulls all his concepts together to help you create a master plan for attacking your own programming problems. His advice is simple, straightforward, and practical. It’s an easy -- and valuable -- read.
A full, free preview of Chatper 6 -- one of the meatier chapters (it discusses recursion) -- is available here.
Think Like a Programmer by V. Anton Spraul; No Starch Press, 2012; 233 pages; $34.95
-- James E. Powell
Editorial Director, ESJ
Posted on 08/30/2012