Who reads code samples? (via Reddit)
Sorry, but I take code samples over mathematical formulas any day. The first example cited in the aforementioned post pretty much confirms this.
The Python example is something I can actually read and understand. I can follow it step by step, understanding what it does at each point. (And if I don’t, I can copy it to a file, stick print statements in it, and examine what it does exactly.)
The formula, on the other hand, is gobbledygook to me. I am a programmer, not a mathematician. To me, the formula is just a confusing mix of (Greek) letters and other symbols. It is essentially unreadable without knowing the context, i.e. the meaning of all those symbols and how they fit together.
(You could argue that the same is true for the Python code — yes, there is context there too, of course, but the difference is that I am expected to know it, as I am a programmer reading a book meant for programmers. It’s not a math book meant for mathematicians or students of math.)
The second example is even worse; the code is longer, but so is the formula, to the point where it’s not only completely unreadable to me, but also sufficiently overwhelming that I won’t even try to figure it out.
It’s cool if you can easily read the formulas, of course. More power to ya. But limiting the examples to formulas makes the text inaccessible to those who can’t read them, or have trouble doing so. Also, you’d still have to translate them to working code (because, again, this is a book for programmers :-).
(I have this book too, by the way… I kinda like it so far.)
Update: Come to think of it, I would much rather have learned math (what little I know of it, that is :-) illustrated with programming examples, rather than using formulas that are so dense that my eyes gloss over the moment I see them. Math would probably have been a lot more understandable and clear back then.
Which makes me wonder, *are* there books that teach math concepts using programming examples? I’m not talking about books like SICP that assume that you already have a firm grasp of mathematical knowledge.