Think Like a Programmer
An Introduction to Creative Problem Solving
Publisher: No Starch Press
Final Release Date: August 2012
Pages: 256

Rewire your brain

Examples in this book are written in C++, but will improve your ability to think like a programmer in any language.

The real challenge of programming isn't learning a language's syntax—it's learning to creatively solve problems so you can build something great. In this one-of-a-kind text, author V. Anton Spraul breaks down the ways that programmers solve problems and teaches you what other introductory books often ignore: how to Think Like a Programmer. Each chapter tackles a single programming concept, like classes, pointers, and recursion, and open-ended exercises throughout challenge you to apply your knowledge. You'll also learn how to:

  • Split problems into discrete components to make them easier to solve
  • Make the most of code reuse with functions, classes, and libraries
  • Pick the perfect data structure for a particular job
  • Master more advanced programming tools like recursion and dynamic memory
  • Organize your thoughts and develop strategies to tackle particular types of problems

Although the book's examples are written in C++, the creative problem-solving concepts they illustrate go beyond any particular language; in fact, they often reach outside the realm of computer science. As the most skillful programmers know, writing great code is a creative art—and the first step in creating your masterpiece is learning to Think Like a Programmer.

Table of Contents
Product Details
About the Author
Recommended for You
Customer Reviews

REVIEW SNAPSHOT®

by PowerReviews
oreillyThink Like a Programmer
 
4.2

(based on 9 reviews)

Ratings Distribution

  • 5 Stars

     

    (3)

  • 4 Stars

     

    (5)

  • 3 Stars

     

    (1)

  • 2 Stars

     

    (0)

  • 1 Stars

     

    (0)

100%

of respondents would recommend this to a friend.

Pros

  • Accurate (7)
  • Easy to understand (7)
  • Well-written (6)
  • Helpful examples (4)

Cons

    Best Uses

    • Student (7)
    • Intermediate (6)
    • Novice (6)
    • Expert (4)
      • Reviewer Profile:
      • Developer (8)

    Reviewed by 9 customers

    Sort by

    Displaying reviews 1-9

    Back to top

    (1 of 1 customers found this review helpful)

     
    5.0

    Learning how to solve problems

    By radu

    from Stockholm, Sweden

    About Me Designer, Developer, Educator

    Verified Reviewer

    Pros

    • Accurate
    • Easy to understand
    • Helpful examples
    • Well-written

    Cons

      Best Uses

      • Intermediate
      • Novice
      • Student

      Comments about oreilly Think Like a Programmer:

      I got this book as part of O'Reilly blogger progam. As a software developer with 14 years of experience myself, I was curious to see what Anton Spraul's book can teach.

      You'll not find there the usual pages with code and algorithms that you'll find in many computer programming books. The code you'll find in C++ and is used mostly for exemplification. Is not a book about code, but one about problem solving. Ideas learned can be applied in many other areas of our life.

      The book starts with basic logic problems (classic puzzles), the solution to them and the way of thinking that can lead to a solution. Here we learn about being aware of ALL possible actions you could take, creating strategies and simplifying the problem, looking for the most constrained part of the problem, recognizing patterns and analogies. Just as a side note, I'm member of a chess site, where paying members get to try a huge number of tactical problems and this helps a lot in recognizing patterns in the real game. Programming is similar: recognizing patterns and reducing complex problems to known ones.

      Then the book goes through specific type of problems in programming, like problems with arrays, pointers and dynamic memory, classes, recursion. Maybe working with pointers is not so current for many programmers, but C++ is still used in a lot of places.

      On very interesting chapter is the one about code reusing. It is teaching when is good and when is bad to reuse code, it helps identifying the components and building a "component toolkit" or component knowledge. It makes use of the knowledge acquired in the previous chapters and interestingly teaches which components to use for a specific problem, based on the amount of work, flexibility and maintainability. It not only presents the way to get to a solution, but also comparing two possible solutions to the same problem and choosing the best one.

      In all the chapters I didn't type in and compile the code, since I was not interested in coding but in finding patterns of thinking and ways to improve.

      The last chapter puts it all together, teaches how to create a development plan by eliminating weaknesses (both coding and design ones) and using the strengths. Also learning a new programming skill is approached systematically and this is approach interesting also for seasoned programmers.

      I'll conclude with a quote from the book: "Once you are thinking like a programmer, be proud of your skills. If someone calls you a coder rather than a programmer, say that a well-trained bird could be taught to peck out code—you don't just write code, you use code to solve problems."

      You can find more details about the book and the table of contents on O'Reilly catalog page.

      (1 of 1 customers found this review helpful)

       
      4.0

      Valuable strategies to boost creativity

      By George Curelet-Balan

      from Kitchener-Waterloo, Ontario

      About Me Developer

      Verified Reviewer

      Pros

      • Accurate
      • Easy to understand
      • Helpful examples
      • Well-written

      Cons

      • Can Be Improved

      Best Uses

      • Expert
      • Intermediate
      • Novice
      • Student

      Comments about oreilly Think Like a Programmer:

      A book with such an intriguing title captured my attention to investigate what approach is taken towards the fascinating area of problem solving in the software programming domain.

      Programming is a complicated endeavor: from figure out a mental approach (algorithm, pattern, etc.) or strategy for a solution and translate it into code, to understand / modify existing code, debug / troubleshoot and find / implement the best way to test the code.

      This book's description reminded me of G. Polya's renowned classic mathematics problem solving book "How to solve it" (http://en.wikipedia.org/wiki/How_to_Solve_It) that some are using it in the software development (http://www.softpanorama.org/Bookshelf/Classic/polya_htsi.shtml).

      Author's goal was to boost programmer's creativity through the gained experience in writing new programs (following his strategies) rather than by reading and modifying existing code. For more details on this you can watch author's O'Reilly Webcast: Problem Solving The Missing Ingredient for New Programmers (http://www.youtube.com/watch?v=ahVgp69xj7I).

      This book presents valuable problem solving programming strategies exemplified by solving simple legacy C++ beginner tasks. For reasons why C++ code before C++11 version is legacy code see Herb Sutter's 2012 talk "(Not Your Father's) C++".

      The author draws lessons from solving classic puzzles (Sudoku, Sliding, "The Fox, the Goose, and the Corn", etc.) and applies them systematically throughout the book.

      While ambitious and general in its title, this book will benefit the most and fastest the beginner legacy C++ or C-like languages programmer (C++ 11 and up versions are not covered / mentioned).

      Intermediate or advanced C-like languages programmers may find value in the creative problem solving approach, some programming idioms or engage with author's ideas like learning creative problem solving, value of C++, managed languages, C++ object-orientation or the component definition / use.

      General considerations about problem solving programming issues and original approach to gradually introduce new topics may justify an interest of programmers / teachers in / of other procedural / object-oriented / functional languages, willing to deal with C++ syntax and idioms.

      Few caveats: 1. Luhn checksum validation problem is incomplete specified but is clarified later by examples and diagrams; 2. use of qsort and C++ Standard Template Library's vector in chapter 3 makes understanding harder (in spite of explanations) since it requires knowledge of C++ pointers respectively object notation explained later; 3. the advantages of object-orientation (object composition and interfaces use) are not enough explored / exemplified, justifiable though by the scope of the book.

      It is laudable author's attempt to decipher the cause of challenges students have in grasping problem solving programming areas and provide valuable guidance throughout the book. In this regard I believe the author met his goal to explain systematic problem solving techniques in order to unlock reader's creativity by practicing them.

      This book contributes towards the goal to fill the gap in the programming literature with such kind of books.

      http://ghcb.blogspot.ca

      Note: this review is based on the ebook version provided via O'Reilly Reader Review Program.

       
      4.0

      Problem solving strategies explained

      By George Curelet-Balan

      from Kitchener, Canada

      About Me Developer

      Verified Reviewer

      Pros

      • Accurate
      • Easy to understand
      • Helpful examples
      • Well-written

      Cons

        Best Uses

        • Expert
        • Intermediate
        • Novice
        • Student

        Comments about oreilly Think Like a Programmer:

        A book with such an intriguing title captured my attention to investigate what approach is taken towards the fascinating area of problem solving in the software programming domain.

        Programming is a complicated endeavor: from figure out a mental approach (algorithm, pattern, etc.) or strategy for a solution and translate it into code, to understand / modify existing code, debug / troubleshoot and find / implement the best way to test the code.

        This book's description reminded me of G. Polya's renowned classic mathematics problem solving book "How to solve it" (http://en.wikipedia.org/wiki/How_to_Solve_It) that some are using it in the software development (http://www.softpanorama.org/Bookshelf/Classic/polya_htsi.shtml).

        Author's goal was to boost programmer's creativity through the gained experience in writing new programs (following his strategies) rather than by reading and modifying existing code. For more details on this you can watch author's O'Reilly Webcast: Problem Solving The Missing Ingredient for New Programmers (http://www.youtube.com/watch?v=ahVgp69xj7I).

        This book presents valuable problem solving programming strategies exemplified by solving simple C++ beginner tasks.

        The author draws lessons from solving classic puzzles (Sudoku, Sliding, "The Fox, the Goose, and the Corn", etc.) and applies them systematically throughout the book.

        While ambitious and general in its title, this book will benefit the most and fastest the beginner legacy C++ or C-like languages programmer (C++ 11 and up versions are not covered / mentioned).

        Intermediate or advanced C-like languages programmers may find value in the creative problem solving approach, some programming idioms or engage with author's ideas like learning creative problem solving, value of C++, managed languages, C++ object-orientation or the component definition / use.

        General considerations about problem solving programming issues and original approach to gradually introduce new topics may justify an interest of programmers / teachers in / of other procedural / object-oriented / functional languages, willing to deal with C++ syntax and idioms.

        My intent was to take a stand from a beginner's point of view and keep an eye on what value an experienced developer could get from the book.

        The introduction chapter makes the plea towards the need for teaching programmers the creative problem solving techniques by emphasizing the lack of guidance in this regard in the programming education. Distinction is made between the two types of programming activities: left brain analytical tasks (code reading, learning language syntax or different APIs) and right brain problem solving by creative use of what was learned. The paragraph on why C++ was chosen is debatable considering the relationship between language vs. thinking and the well-known fact that each programming language has its own idioms and strengths in mapping mental concepts into code (justifying the multitude of "Thinking in ..." languages books). Debatable will be though any attempt to claim language independence approach to explain problem solving programming concepts considering the daunting task of such an endeavor.

        The first chapter on "Strategies For Problem Solving" draws lessons by solving few classic puzzles mentioned above. Here are some of the problem solving lessons shared in the book:
        - try methodically and backtrack to previous steps
        - plan / use a systematic approach and avoid frustrations
        - experiment with a reduced (in size) version of the problem
        - use intuition to select the right solving tip for specific problems
        - enumerate allowed operations and test them in search for a solution
        - recognize analogies with other solved problems by studying the problem
        - consider all of the problem's constraints instead of avoiding some, just to solve it
        - think about the problem by restating / generalizing it eventually to gain insight for a solution
        - divide and conquer (breaking down the problem into easier sub-problems, helps solving it (if successful) or gives insights for a solution, if it fails)

        The next chapter (Pure Puzzles) exercises some of above problem solving techniques by dealing with elementary C++ tasks like: printing different output patterns, processing input in the Luhn checksum validation problem and tracking state in a message decoding problem. The problem solving techniques used are: divide and conquer, systematic use of problem scope reduction, experimentation, start from what you know, analogy with solved problems, following a plan, avoiding frustration, understand the problem and generalization.

        Chapter 3 deals with solving problems using different types of arrays: fixed / dynamically sized, scalar / non-scalar and multidimensional. Besides ways to approach these problems there are presented and analysed implementation reasons and when array use is appropriate. The topics of refactoring and space / time performance of programs are introduced alongside.

        The delicate topic of solving problems with pointers and dynamic memory, specific to legacy C++, is discussed in the next chapter. I disagree with the author statement that learning pointers use is essential to truly think like a programmer. As such I don't think that generally pointer less C-like languages (Java, C#, etc.) programmers will get much value from this chapter (excepting the challenge of following the C++ specific problem solving approach). Topics covered: when to use pointers, stack and heap memory, variable's lifetime, memory leak, variable length strings, solving by sample case, checking for special cases, code robustness and linked list specific problems like building, node adding and traversal.

        Chapter 5 is about object-orientation and solving problems with classes. A beginner might have hard time understanding the chapter's first part that reviews class fundamentals and the goals of class use due to general nature of exposure used (areas sometimes covered by entire books). In contrast, the next part of the chapter shows through an example how to build a simple class and solve object-orientation implementation issues. This is followed by a more advanced example of a class implementing linked list operations. Readers not willing to become familiar with pointer concept will not benefit from this. While author's decision to use this example might be justified as a follow up of previous chapter linked list coverage I believe that the spirit of exposing object-oriented problem solving technique might have been better served by an example outside of C++ specific pointer concept.

        The challenging new way of recursive thinking is originally covered in the next chapter. Author's goal is to make recursion simple by following a systematic approach. Two detailed explained original examples illustrate the head and tail recursion preparing the ground for introduction of the Big Recursive Idea. A very simple example of array summation is used to explain the Big Recursive Idea of transforming an iterative solution into a recursive one. Common mistakes of using too many parameters or global variables are clearly explained and exemplified. Next, the recursion use with linked lists and binary trees are exposed via two simple C++ pointers based examples. The need for public wrapper functions when class implementations use recursion is exemplified by solving a binary tree C++ problem. The chapter ends by discussing and exemplifying the pros and cons of recursion use.

        Chapter 7 details an interesting approach towards solving problems through code reuse. Some might argue on the author's definition of reusable component, that includes both low-level artifacts (code block, abstract data type and library) and high-level ones like algorithms and patterns, but it serves well his purpose. Building component knowledge strategies (exploratory vs. as-needed) are exemplified with specific coding problems. While the example of use of analogy during the "as-needed" component use strategy is instructive I find its application quite unrealistic since a priori effort of learning component's capabilities is required. The tradeoffs made while choosing a component type are exemplified by two alternative implementations of a sorting problem. A modified insertion-sort algorithm component implementation is compared and analysed against a qsort C++ library component call.

        Last chapter guides the reader to develop his custom problem solving plan and continuous learning strategy that will allow her / him to tackle any problem. This involves identifying of coding (design) weaknesses / strengths and build a master plan by planning against / for them, respectively. Next, the process of building a sample master plan is detailed. How to put the master plan to work is detailed exemplified through solving a non-trivial problem.

        The author's extensive teaching experience is revealed in the chosen increasing complex topics and well documented presentation (question / answer and diagrammatic) style that sometimes is too elementary / verbose, justifiable though considering book`s broad scope. This style is sometimes contrasted with advanced programming statements, like the use of Standard Template Library or general statements that might challenge content understanding by a beginner.

        Few caveats: 1. Luhn checksum validation problem is incomplete specified but is clarified later by examples and diagrams; 2. use of qsort and C++ Standard Template Library's vector in chapter 3 makes understanding harder (in spite of explanations) since it requires knowledge of C++ pointers respectively object notation explained later; 3. the advantages of object-orientation (object composition and interfaces use) are not enough explored / exemplified, justifiable though by the scope of the book.

        It is laudable author's attempt to decipher the cause of challenges students have in grasping problem solving programming areas and provide valuable guidance throughout the book. In this regard I believe the author met his goal to explain systematic problem solving techniques in order to unlock reader's creativity by practicing them.

        This book contributes towards the goal to fill the gap in the programming literature with such kind of books.

        Note: this review is based on the ebook version provided via O'Reilly Reader Review Program.

        (5 of 8 customers found this review helpful)

         
        3.0

        For Students Only

        By dominickm

        from Eatontown, NJ

        About Me Developer

        Verified Reviewer

        Pros

        • Accurate

        Cons

        • Too basic

        Best Uses

        • Student

        Comments about oreilly Think Like a Programmer:

        This book is aimed a Computer Science and Software Engineering students and I am neither of those things; I'm at the point where I knew most of the overarching concepts in the book and the ones I didn't proved to be little more than the type of trivia that "engineers" feel separates them from the unwashed masses — ie the rest of us. In all fairness, V. Anton Spraul is very knowledgeable and that comes through clearly throughout the book.

        Just know going in that you may not be the target audience for this book.

        (4 of 4 customers found this review helpful)

         
        4.0

        Solving strategies...

        By Andreas Masur

        from United States

        About Me Developer

        Verified Reviewer

        Pros

        • Easy to understand

        Cons

        • Not comprehensive enough

        Best Uses

        • Intermediate
        • Novice
        • Student

        Comments about oreilly Think Like a Programmer:

        Software development has never really been easier than today. There are programming languages available for virtually any domain; many of them abstracting most of the core language details away to let the programmer focus on the actual problem.

        But even with the added abstraction, finding the most elegant and efficient way of solving a particular problem is still the real challenge when it comes to writing software. V. Anton Spraul's book focuses exactly on this part by teaching a set of strategies that can be applied to solve both simple and complex problems effectively.

        The books starts by looking at common problems such as the fox, the goose and a bag of corn, sliding puzzles, Sudoku etc. and deriving some techniques and principles on how to solve them efficiently and effectively. These core idioms are not related to any programming language but rather a generic set of strategies for tackling problems.

        The next chapter then takes these techniques and principles and applies them to simple programming problems. While the problems are pretty basic, it helps keeping the focus on the actual problem solving rather than the programming language used.

        The following chapters introduce various elements and concepts of programming languages such as arrays, pointers, classes, recursion etc. and show how they work, can be manipulated and used in order to solve particular problems. The chapters are definitely more intermediate and vary in difficulty; especially for people who do not really know or understand C++.

        The final chapter reflects on all the strategies introduced and essentially brings them all together. Every developer has different strengths and weaknesses so there is no generic plan on solving problems that works for everybody the same. It is all about creating a personal plan on how to analyze, tackle and ultimately solve both simple and complex problems.

        Finding a verdict for the book is not easy though. Overall, the book does a pretty good job to introduce the reader to common strategies on how to analyze, tackle and solve programming problems. Unfortunately, the majority of the book rather focuses on particular elements and concepts of one programming language, which - while ultimately still relevant - are rather topics specific to programming rather than general problem solving. The choice of the C++ programming language for all the examples also poses another hurdle: It certainly increases the barrier for readers coming from different languages that may not be really familiar with C++. Some of the concepts in C++ are different in other languages, especially interpreted ones, which may make it a bit harder to actually understand the underlying concept.

        In conclusion, the heavy reliance on the C++ programming language makes it a good recommendation for any developer familiar with C++ who is looking to improve his/her ability and skill to solve problems efficiently. Anyone looking to rather find a more generic approach to creative problem solving will have a harder time to gain the same amount of knowledge out of the book though.

        (2 of 2 customers found this review helpful)

         
        5.0

        "Think like a Programmer" by V.Anton Spr

        By Sac

        from Singapore

        About Me Developer

        Verified Reviewer

        Pros

        • Accurate
        • Concise
        • Easy to understand
        • Well-written

        Cons

        • Not comprehensive enough

        Best Uses

        • Expert
        • Intermediate
        • Student

        Comments about oreilly Think Like a Programmer:

        Being from a Non C++ Background, this book is a pleasant surprise.The book caters specifically to Programmers who struggle to write Code from a Scratch. How many Authors have attempted to do that? None so far as i can remember. Lessons learnt from the numerous puzzles in the book are truly inspirational and eye opener
        The author gives important key points like always having a plan, restating the problem,dividing the problem etc. No answers are given though for the numerous puzzles in the book which could be a letdown but it does attempt to make any person reading this book use his brains to hunt for Solutions. This is an important asset for any aspiring programmer. Thus I would highly recommend this book only for this reason no matter what language you have been using or how long you have been programming. This book is a must for everyone involved in IT.
        Spraul, the author does an impressive job with this book and how i wished i had come across this book at the beginning of my career.

        Bottom line : yes, i will recommend this book to anyone involved in IT, Developer,Architect, Project Manager etc

        (4 of 9 customers found this review helpful)

         
        5.0

        Programando en la vida real

        By DGGONZALEZ

        from Buenos AIres. Argentina

        About Me Divulgador

        Verified Reviewer

        Pros

        • Easy to understand
        • Well-written

        Cons

          Best Uses

          • Expert
          • Intermediate

          Comments about oreilly Think Like a Programmer:

          Uno de los mayores obstáculos a la hora de aprender a programar son los cursos de programación. Uno comienza lleno de ganas que van disminuyendo despúes de varios capítulos en los que le enseñan a escribir "¡Hola Mundo! en la pantalla y otras cosas inútiles semejantes. Si logra terminarlo con suerte sabrá interpretar código escrito por otras personas y adaptarlo a sus necesidades.

          Think Like a programmer utiliza un enfoque diferente, enseña al usuario a analizar los problemas a los que se enfrentan más a menudo los programadores novatos y como aprender a resolverlos usando su cerebro.

          Tal vez puede objetarse que el lenguaje elegido, C++ en lugar de por ejemplo Python dificulte el acceso a los lectores principiantes que son quienes más necesitan de este libro

          (1 of 1 customers found this review helpful)

           
          4.0

          Good for beginners

          By Andy

          from Germany

          About Me Developer

          Verified Reviewer

          Pros

          • Accurate
          • Well-written

          Cons

            Best Uses

            • Novice
            • Student

            Comments about oreilly Think Like a Programmer:

            V. Anton Spraul is an experienced computer science teacher and has taught introductory programming and computer science for more than 15 years.

            The goal of this book is to teach you the creative Part of programming. It's target audience are clearly beginners who "struggle to write programs, even though you think you understand programming languages."
            You should be familiar with at least one Programming language (it doesn't have to be c++).

            The book starts with some general problem solving techniques (e. g. always have a plan, divide and conquer) and explains them on some general puzzles.
            In later chapters Problems will be solved with specific programming concepts like Arrays, pointers, dynamic memory and recursion.

            You might be disappointed because Spraul doesn't give any answers to the exercises but as Spraul states at the beginning of the book you should see them as opportunities to apply the concepts described in the chapters.

            The exercises are coded in c++ but the book is not specifically about c++. Most chapters start with a short review of the used concepts in c++.

            (7 of 8 customers found this review helpful)

             
            4.0

            Critical thinking and problem solving

            By David Ruttka

            from Chelsea, AL

            About Me Developer

            Verified Reviewer

            Pros

            • Accurate
            • Easy to understand
            • Helpful examples

            Cons

            • Too basic

            Best Uses

            • Novice

            Comments about oreilly Think Like a Programmer:

            Experienced computer science teacher V. Anton Spraul guides the reader in how to "rewire" the brain for problem solving instead of rote typing. As the back cover puts it, "The real challenge of programming isn't learning a language's syntax - it's learning to creatively solve problems..."

            The book starts with a general discussion of problem solving, removed from the specifics of programming. It may seem overly familiar to some, but I believe that even experienced problem solvers can find joy in Spraul's delivery of the universal techniques.

            The middle of the book took me back to 200-level college CS courses. I'll have to be honest that I only skimmed these chapters, as the I've been working with arrays, pointers, recursion, etc. for over a decade. For those who are just beginning, or might have come from a more business related course of study, this is tremendous stuff! If you don't know the difference between head and tail recursion, the stack and the heap, or have never traversed a binary tree before then please do read!

            My favorite part of this book is that no answers are provided for the exercises at the end of each chapter. This drives home the point that we must learn to think through our problems and solve them ourselves. A chapter is dedicated to "good reuse" vs. "bad reuse", where one of the main differentiators is whether you're reusing the code to learn from it or to avoid thinking.

            Another great section was the final chapter, where Spraul visits the idea that each brain is different, and we might all apply the universal strategies in different ways. Then he walks us through his specific thought process for a newly presented problem, and how we can become continual learners.

            Negatives? Not many. As above, more experienced readers might find discussion of sorting arrays a bit tedious. The examples are in C++ which could frighten some, but be assured that the code is written to be readable even if you have little familiarity with the language. Spraul gives some reasoning in Chapter 5 (Classes) for why C++ was a good choice, and of course you can work through the exercises in any language you wish.

            Spraul seems to be an expert teacher of problem solving. I highly recommend this book to anyone who feels stumped when facing a new problem or could use some pointers on how to teach others who do.

            Displaying reviews 1-9

            Back to top

             
            Buy 2 Get 1 Free Free Shipping Guarantee
            Buying Options
            Immediate Access - Go Digital what's this?
            Ebook: $27.95
            Formats:  ePub, Mobi, PDF
            Print & Ebook: $38.45
            Print: $34.95