views:

607

answers:

13

So lately I've been trying to learn to program. It's quite clear that the best way to learn will be by doing. What I find odd is the structure of programming books (or educational materials) don't support this notion. Even the most interactive resources I've found (why's Try Ruby, Eloquent Javascript, etc) follow a structure like this:

  1. describe concept
  2. demonstrate application (sometimes)
  3. provide a related exercise (sometimes) with solution (sometimes)

A typical (basic) math book, and what I'd like to find in a programming book, goes something like this:

  1. describe concept
  2. demonstrate several applications
  3. provide 30-50 related exercises of increasing difficulty
  4. provide solutions (with explanations) to most or all of the exercises

Math books usually don't provide explanations, but I think they would be helpful in a programming book.

It may not be pretty, and math books often use terrible exercises (especially the "real-world" exercises), but if you sit down and work through all of them, you will learn.

Programmers often say, "Just start a project." I've found that's a good way to learn how to do a particular project, and a good way to learn how to piece together frameworks and plugins and libraries, but not necessarily a good way to learn how to program (I understand all of that is part of programming, but I think there's a self-sufficiency that I'm looking for that is separate from the piecing together of things).

At any rate, does anyone know of a resource that's closer to the math book style (preferably Ruby or JS)? Is there a reason why programming books aren't written in that format?

A: 

Try your university bookstore. Typically the books there have the style similar to what you're describing.

Most books in the field are meant for professions, and the idea is that instead of exercises, you have a real world problem to solve.

glowcoder
+6  A: 

I can't offer any specific book suggestions. However, since you seem mathematically-oriented, and are looking for programming problems of increasing difficulty in order to master (or just learn) how to program in a certain language you could pick a language, and work on the problems at project Euler: http://projecteuler.net/

You will not be working with databases/GUIs when you solve these problems, but these sorts of problems (and their solutions) will teach (and give you some intuition) some fundamentals of algorithm design. Once you feel fairly comfortable with that, you could try some of the certification-test training books (for example, the Microsoft Certified Professional Developer books). They are more like the books you said you are looking for (concept followed by tons of examples/exercises) since they are meant for test preparation. However, these books can teach you about leveraging libraries and developing GUIs or databases but not about the fundamentals of programming. You shouldn't start with them (since they don't cover the basics I feel every programmer should know).

Hope this helps.

Assaf
A: 

Well, programming books usually aren't meant to be read on a desk with a notebook. Most developers want to just open the book, continue reading where they left and learn something new, the math book format isn't the most suited for this.

DrunkenBeard
+5  A: 

How to Design Programs is structured very much like a math book, and it's online for free thanks to the MIT Press. Each chapter features a lot of exercises - there are even additional problem sets if you want more to work on. Most exercises are math-based. It uses Scheme, a dialect of Lisp that MIT used to use in CS intro courses (I understand they've begun using Python in the last few years). I did several chapters of HTDP while concurrently learning Ruby, and found the concepts and ideas immediately applicable to my Ruby coding.

If you want something that uses Ruby right off the bat, try Learn to Program, which ends each chapter with several exercises that test your knowledge of material covered in the previous chapter. It's geared towards people entirely new to programming.

Another great resource for learning to program is MIT's OpenCourseWare, particularly 6.00 Introduction to Computer Science and Programming. It features video lectures, assignments, and exams with solutions. Assignments are math-intensive.

michaelmichael
A: 

The books that you've tried are books that will teach you one programming language, not how to program.

If you want some book that will teachs you how to program I'd suggest one of the Sedgewick's Algorithms in C++ (or Java or Pascal or anything, the language isn't what matter) and if you want to go to more hardcore stuff you could try Introduction to Algorithms (Cormen) and The Art of Computer Programming (Knuth).

These last ones are in fact more a math book than a programming book

Ed
A: 

It's not hard science.

Each problem is in a way blurry and can have a number of solutions. You can evaluate the solutions by answering questions like: What computational complexity does it have? Is it elegant? Is it reusable? What frameworks and techniques does it use?

There's more than one way to do it and too many criteria, techniques and approaches to take. In most cases it's not feasible to provide a set of exercises. That's why most books on programming or software development use something like "case studies" or lengthy problems developing over time rather than simple exercises.

Konrad Garus
+8  A: 

In my opinion, the incarnation of "programming books that are like math books" is Donald R. Knuth's "Art of Computer Programming". However, it uses MMIX and not Ruby or JS.

Peter G.
+9  A: 

I'd guess that SICP aka Structure and Interpretation of Computer Programs, is probably the closest to what you're looking for.

Most 'professional' books that you see in your chain bookstores are little more than extended HOWTOs, and frankly aren't worth anyone's time as a serious student. You can tell the worse books from the better by the copious use of glossy pages, full-color diagrams, not as much text, and cutesy icons. O'Reilly books are usually excellent HOWTO books - I can't say that I've ever heard of them actually publishing a 'computer science' book. That is not a criticism, that is an observation of their focus. Aspell also has a good reputation for the more HOWTO side of things.

Most 'Intro to programming' books are beyond awful. When I was learning programming, I had something like fifteen different 'Intro to C++' type books stacked up on my floor, of which I thought only Jesse Liberty's books were decent(ironically, those were in the Learn X in Y hours series). I also have found good use from one of Schildt's books on C++("The Complete Reference"), but Schildt has a poor reputation, I later learned.

You will want to find a book on data structures, a book on algorithms, and an indepth book for your chosen languages syntax and semantics. You will almost certainly not find these books physically outside of a university bookstore or a specialty tech store like Powell's Technical Books in Portland. Amazon is your best bet.

For algorithms, I would suggest Sedgewick or Baase, and then, later, Cormen's book as a permanent reference.

For data structures, I haven't found a really good book - I'd assume that Aho, Ullman, and Hopcroft is at least solid. However, be aware it's a little dated and doesn't cover the more exotic structures that have been invented in recent years.

For your chosen language, you will want something like Strousoup's The C++ Programming Language.

Best of luck. Do update this question with the book you find that is most helpful, please.

Paul Nathan
+1 for SICP and Powell's Technical Books in Portland
Wilduck
SICP is a very good book but I cannot remember the exercises being accompanied by solutions.
Peter G.
@Peter: It's a guess. I have not sat down and read the totality of the book.
Paul Nathan
+2  A: 

From The Structure and Interpretation of Computer Programs:

Underlying our approach to this subject is our conviction that "computer science" is not a science and that its significance has little to do with computers. The computer revolution is a revolution in the way we think and in the way we express what we think. The essence of this change is the emergence of what might best be called procedural epistemology -- the study of the structure of knowledge from an imperative point of view, as opposed to the more declarative point of view taken by classical mathematical subjects. Mathematics provides a framework for dealing precisely with notions of "what is." Computation provides a framework for dealing precisely with notions of "how to."

Although solutions to programming problems often embody numerous mathematical concepts, programming is often more like writing and art than it is mathematics. Just as no two writers will author identical 500 word essays, no two programmers will write the same software. Similarly, it's virtually impossible that even the one author will create an identical work two times in a row.

You wrote, in comment:

@Dan — I suppose more along the broader lines of software development/engineering...learning how to take a given problem and program a solution by starting with very small problems and gradually increasing the complexity

This sounds exactly like test-driven development to me, so I'd recommend the following books as referenced in this stack overflow thread:

Although I haven't yet read it, I've heard many good comments about Growing Object-Oriented Software Guided by Tests, so it's first on my list.

Kaleb Pederson
Please explain the downvote. Thanks.
Kaleb Pederson
Don't know. This is one of the more insightful answers to the question.
James
+2  A: 

Interestingly, a friend and I were just talking about this yesterday, and to some degree, I disagree, but on the larger scale. First, I'll offer my opinion that in the past few years, I greatly prefer PDF copies of development-forward programming books, because I can search, non-destructively annotate/highlight with most tools, very often am able to follow links from the document directly, and if need be, copy and paste large chunks (though retyping them is often an exercise in memorization/understanding). _why's guide is somewhat close to this, but it's meant to be an idiomatic, narrative introduction, not a rigorous primer.

Now, back to my friend. My original contention was that math books, and courses in general, start with the supposition that you need to build your tools to understand them. You don't start by learning how to use a derive(expr) function and what to expect from its use, you learn algebra, then abstract algebra, then build the tools of the calculus to derive things yourself. This isn't strictly necessary in programming. I'm sure it helps in some way that I've read the BigTable paper before diving into Google App Engine, but it certainly isn't necessary. In my mind, a good programming book will encourage you to try things not yet covered in the book, but be rigorous enough to reel you back in before spending hours realizing That's Not The Way You're Supposed To Do It (though There's More Than One Way To Do It).

These are just my two cents, as I've been thinking about the broader scope of programming books lately, and mercifully, as others have mentioned, there are great publishers out there that foster a more cerebral than procedural approach, like Pragmatic Programmers, Manning, etc. I haven't read SICP, but others have suggested that it's similar to the "math book" method, but even Introduction to Algorithms was much more like the programming books you've described. In my mind, Design Patterns is the flagship example of the sort of book you don't like; basically just a catalog of concepts roughly grouped together, with some discussion of what they do and some examples of how they're used. I reserve a great deal of deference for it and the authors, but it's certainly more a reference than anything else.

Marc Bollinger
A: 

The book that jumped to my mind when reading your question was:

The C Programming Language

It's not the languages you asked for, but it is really a classic programming book. The subtly of the book actually comes in the exercises... which MUST be done to really understand the lesson. While the answers aren't in the book itself, there are readily available.

Richard Morgan
+3  A: 

I found Robert Lafore's "Data Structures and Algorithms in Java" book quite useful. It's not exactly a classic, but it does enough hand-holding so that I was completely able to work through it on my own. Every chapter has exercises and the book gives you a nice series of understandable but challenging exercises.

morgancodes
A: 

Check out "Purely Functional Data Structures" by Chris Okasaki. It's a gem.

Rafe