Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Programming books that are more like math books?
31 points by blehn on July 21, 2010 | hide | past | favorite | 19 comments
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[1]) to most or all of the exercises

[1]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?



Anything by EWDijkstra or CAR Hoare or David Gries.

The Science of Programming by David Gries was very good, it covered some maths needed for programming such as set theory and then it used its own programming language (based on Dijkstra's) to discuss programming language concepts that may come up. It had a great little section about deriving conditions based on loop invariants. Also there's a section on Predicates. Basically it covers all the stuff you'll need to know when using any programming language and that programming language tutorials fail to discuss.

You can see a preview at Google Books: http://books.google.ca/books?id=vv5pot-ySsEC&lpg=PP1&...

There's also A Discipline of Programming by Dijkstra and I love that one too. He has examples of great algorithms and the way he develops them is awesome: http://www.amazon.com/Discipline-Programming-Edsger-W-Dijkst...

The reason books like that aren't written is because they're too academic for some peoples' tastes. Unfortunately, books like Head First or whatever else, sell like hot cakes because they appeal to the lowest common denominator of programmer, the one whose eyes glaze over whenever there's math involved (that's usually the North American programmer, Europeans (at least the French and Dutch) don't mind the math).

I also think a lot of people dislike books with several exercises because they add way more pages. You don't need 3-5 pages of exercises, older math books only had 0.5-2 pages of exercises. Older math books are also not cluttered like the modern textbooks.

You could also do what Dijkstra did, which was write. Think and write about your experience, think and write about how you will approach a problem and explore alternative solutions, etc. Make up your own little notation for programming so you can free yourself from worrying about some obscure syntax or library call in a language.


I learned many concepts by spending years designing, building, redesigning, and rebuilding many... many... many... times. Then I got this book:

3D game engine design: a practical approach to real-time computer graphics By David H. Eberly

and my universe was changed forever. Pick a project that you think is worth it and go through the pains of building something that you think is beautiful. This is how you become a good programmer because your art will drive you.

Keep in mind, to become a professional is to put away the art brushes and grab a shovel because most of the problems professionals deal with are not programming related but rather drama-driven-bullshit.


Two good books which are in the sort of style you seek are:

The Little Schemer <http://www.amazon.com/Little-Schemer-Daniel-P-Friedman/dp/02...; and

Clause and Effect <http://www.amazon.com/Clause-Effect-Programming-Working-Prog....

Also a help is that the languages they use ('use' is a more appropriate word here than 'teach') — Scheme and Prolog, respectively — are much more mathematical in nature than typical mainstream languages are.


I second Clause and Effect. (The Little Schemer, too, but CAE doesn't get much attention.)

Sterling and Shapiro's _The Art of Prolog_ is also excellent, though you'll probably be better off reading _Clause and Effect_ first if you've never used Prolog. CAE is all about getting a feel for how Prolog operates, step-by-step* , while TAoP is about the logic programming paradigm, interspersed with project case studies and comparisons between Prolog (as an LP implementation with various compromises) and "pure" LP.

* This is the main thing it has in common with The Little Schemer: both begin by stepping through their respective languages' evaluation at a micro-level, until the semantics feel totally clear. This is especially helpful since Scheme and Prolog are both very different from the typical imperative/OO languages people know.

FWIW, The Little MLer is written in the same style as TLS, and is a good, lightweight introduction to ML's type system / static typing.


Also, if for whatever reason you have a hard time grokking Prolog, there's also an excellent chapter on LP and Prolog in CTM.


this is sort of discrete math with haskell examples

http://www.amazon.com/Haskell-Logic-Maths-Programming-Comput...


Most language books and language tutorials are NOT written for beginning programmers. They assume you get concepts like flow control (branching, looping, etc), functions, recursion, and data structures. Even if they cover (e.g) "what is branching" it is almost always from viewpoint of "here are the specifics of my language". Basically, they assume a certain level of programming knowledge.

Advice like "just do a project" is good, but again, it is geared towards people with a certain level of understanding. However, it also works for novices, albeit more painfully. A lot of what you say about 'piecing together' vs 'self sufficient programming' is a perception problem, namely the missing ingredient for you is experience. The rest is learning about algorithms, how to make them, how to understand them, etc.

One thing, here, before getting too far, is that the language doesn't matter as much as outsiders think -- sure it is important, but a good conceptual grasp is far more important, because at some point picking up languages is fairly easy. (not trivial, but..)

So all of that being said, I don't know of any programming books which follow the format you describe, but I can recommend a couple of resources that approach the concepts instead of the language. The first is a series of books called "How to think like a computer scientist"[1]. The second is the MIT scip lecture series[2]. Neither is in your preferred languages, but both are great intros.

[1] http://www.openbookproject.net/thinkcs/

[2] http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussma...


I'd like to second SICP and specifically the accompanying book - available online at http://mitpress.mit.edu/sicp/full-text/book/book.html


I don't know how likely you are to find "math book style" Ruby or Javascript books. Some language communities have academic (Haskell, ML, Scheme) and/or mathematically savvy (APL!) cultures, and some just don't.

There are some great suggestions here already, and I'd also recommend Pierce's _Types and Programming Languages_ and Knuth et. al's _Concrete Mathematics_.

Also: http://projecteuler.net/


Elements of Programming by Alexander Stepanov and Paul McJones (Hardcover - June 19, 2009) might be what you are looking for. Read the Amazon reviews.

And, of course, there is always Knuth's Art of Computer Programming in any of its many editions.


K&R2 is the best example that comes to mind. The solutions to the exercises are not included in the book, but there are many websites with various solutions and discussion.


A lot of learning is by rote - doing something over and over again until it is drilled into your little f'ing brain.

With math, the end objective is to learn the material for the sake of learning the material. If you love math, that may be a reward in of itself, but I think that for the majority of people, this means that we're drilling it into our heads with no other objective than to pass a test, complete the course, and prepare ourselves for the next class that further builds upon the concepts. We usually don't have a real world application for our newly acquired math knowledge.

With programming, on the other hand, there is a real world application of our knowledge. Applications! (Pun kind of intended.) So the learning by rote that we do, is going out and applying the knowledge to the development of real software programs. If you're really excited about programming, once you're introduced to the concepts, you want to create something of your own, not labor through a bunch of (often tedious) mock examples.


Some classic AI books sort of take this approach, introducing concepts followed by small programs, followed by more concepts, followed by building up more complex programs, etc. They aren't mainly PLs books, but they serve as Lisp intros as well. Traditionally, teaching Lisp and teaching AI was done as an integrated process, which is an approach that gives the PL side some built-in, non-contrived examples to use. However, the focus is admittedly very much on the AI, and Lisp gets introduced sort of in passing, when needed.

Two examples (code examples/solutions linked) are Paradigms of Artificial Intelligence Programming (http://www.norvig.com/paip/README.html) and Building Problem Solvers (http://www.qrg.northwestern.edu/bps/directory.html).


Programming as a discipline is still a largely of an experimental nature. This is not a value judgment one way or the other. But padding out books in order to look more comprehensive is an old trick and is not really the same discussion topic. That has largely been addressed by many things including those publishers who are successful precisely because they do the opposite. Other than that this seems to be a blanket generalization and criticism causing other generalizations and criticisms to spring to my mind, Ivory Tower is one of them ;-)

Having said that, I think that you might be missing the point that the reason for all those examples, even if they are weak in many cases and reasonable to subject to great criticism, is because the practice of programming is how you learn how to program. Reading a book is not oh young rabbit.


Based on the title I thought you were going to complain about algorithm descriptions that are written in math notation (like where loops are written as summations, and there are lots of greek symbols).

I know these always bugged me in school. I guess some people think in this notation, but I always preferred pseudo code.


I think you might be more interested in textbooks. In the programming world, the 'start a project' or build a software, it's more like a math theorem, not an entire branch of math. You find the solution to a problem, which basically in math you do by applying 1 or more theorems/solutions that have been found before.

Unfortunately I don't know of any programming textbooks (for programming languages, similar to math books), but CS texts: Structure and Interpretation of Computer Programs (as mifrai suggested); better to follow courses http://ocw.mit.edu/courses/electrical-engineering-and-comput...


For general programming concepts, there are many books with exerices, like sicp, essentials of programming language, etc. For books about specific programming languages, there are many quizzes online that you can use, just search for "language quizzes". Also project euler and similar websites may help.


Project Euler is a great start if you want a corpus of exercises with answers.


SICP, EOPL, Lil/Seasoned/Reasoned Schemer




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: