Book Review: The Nature of Code 37
eldavojohn writes "I kickstarted a project undertaken by Daniel Shiffman to write a book on what (at the time) seemed to be a very large knowledge space. What resulted is a good book (amazing by CC-BY-NC standards) available in both PDF and HTML versions. In addition to the book he maintains the source code for creating the book and of course the book examples. The Nature of Code starts off swimmingly but remains front heavy with a mere thirty five pages devoted to the final chapter on neural networks. This is an excellent book for Java and Processing developers that want to break into simulation and modeling of well, anything. It probably isn't a must-have title for very seasoned developers (unless you've never done simulation and modeling) but at zero cost why not?" Read below for the rest of eldavojohn's review.
First off, I feel like defining the audience of this book is very important to avoid disappointment. This book is not for someone who's already developed games or modeled highway traffic or knows how to build their own physics engine. No, this book is geared at the people who are familiar with one language (preferably Java or Processing) and want to get a taste of all of the above. This book is possibly suitable for a someone new to the world of programming who is willing to put in the extra effort of coming up to speed on Processing in tandem with the text. After all, Processing is a comparatively forgiving language with a dead simple API to interact with the mouse and draw/animate objects. The Nature of Code: Simulating Natural Systems with Processing | |
author | Daniel Shiffman |
pages | 520 |
publisher | The Nature of Code |
rating | 9/10 |
reviewer | eldavojohn |
ISBN | 978-0985930806 |
summary | A book concentrating on the simulation of natural elements through both basic and advanced programming concepts in Processing. |
I'd also like to address the "exercises" that are found throughout chapters and at the end of chapters in this book. They are excellent. I picked a couple and invested actual time in fleshing them out and I feel like Shiffman succeeded in inserting a wide range of difficulty. Leading along through each chapter, it is easy to successively complete each new exercise while the end of the chapters present stretch exercises. In addition to that, applicable chapters urge and provoke the reader to utilize newly learned concepts into what Shiffman calls "The Ecosystem Project." Where the user is basically defining an ecosystem and continually adding new animals, new movement patterns, new behaviors like predation and finally artificial intelligence.
Lastly this book can be found in many formats and I read the first half as HTML with animated diagrams. While the animated diagrams were awesome and added greatly to the text, I still found myself enjoying the dead tree book much more. I know I will soon be a dinosaur with shelves of needless weight that people will mock but I cannot make the jump to reading on a screen. The book's binding and paper quality is average as it appears to be from Amazon's CreateSpace. Diagrams that would animate are shown in the book as having progressively darkening shadows of the paths of objects and is fairly easy to envision movement. I did love the HTML version's moving examples though!
The introduction of this book brings up a few fundamental concepts on randomness like random walks and Perlin noise as well as a bit of statistics. For being labeled "Introduction" this chapter is fundamentally important and the aforementioned concepts are referred back to throughout the rest of the book. The book immediately dives into code snippets of a very simple nature that are easy to run and understand. Great detail and careful explanation are found throughout these opening chapters. The user is given informational boxes going further in depth to certain concepts. This was done really well in the first five or so chapters and was rare if even present in the final chapters.
The first chapter is devoted to vectors. It does an excellent job of explaining why they are so important as well as define and code mathematical concepts that affect vectors. A great aspect of this chapter is that the author fleshes out PVector functionality before your eyes to better understand Processing and object oriented programming. New (to beginners) ways of representing and implementing velocity and acceleration using vectors are explored at their most basic levels.
The second chapter moves naturally enough to forces on objects and begins to delve in basic physics formulas. Newton's Laws are modeled as well as friction, aerodynamics, fluid dynamics and gravity. Shiffman does a great job of keeping these unruly topics in easy to understand language while at the same time offering the scary looking formulas. He even goes so far as to insert an informational box imploring the reader to not be afraid of scary looking formulas by breaking down friction. I feel like one of the strengths of this book is showing how a complex looking formula can be deconstructed to easy English and then further implemented roughly in a model in Processing. While this modeling is by no means completely accurate or state of the art, it is a good introduction and would likely suffice for simple games and web design.
The third chapter brings angles into the mix by concentrating on oscillations. While it does a great job of talking about the important aspects of trigonometry, the text does really follow through with recalling these concepts. For instance, the mnemonic device SOHCAHTOA from geometry class is briefly explained and subsequently dropped. We use it in later chapters but it is used implicitly and may be difficult for people who are not intimately familiar with it to see the trigonometric reductions employed for simplified coding of the visualizations. Shiffman does an excellent job at starting with something that looks like a complex system, breaking it down to its component vectors and showing incremental changes to the code that iteratively improve on the visualization at hand. In doing so he gives an example of how a modeling programmer should think and work through known physical behavior to derive something that works visually in Processing.
Next up is particle systems. The reader is introduced to simpler ways of maintaining a set of particles as we start to focus on multiple particles with complex interactions. Shiffman opts to keep it simple and shies away from coding aspects like ArrayList versus LinkedList versus HashMap. Instead minimal space is spent on side ventures and the particle systems are surprisingly easy to get off the ground. The user is introduced to polymorphism, inheritance and more advanced class constructs so that the user can reduce the amount of code required to activate, handle and delete heterogenous groups of particles. For a beginning developer this chapter is great at walking them through these more advanced concepts and helping them see a direct benefit to the code.
So far, Introduction through Chapter Four of the book, everything has been great. Shiffman points out that there are a plethora of physics libraries out there in any imaginable language of any imaginable quality. And, consequently, it's unlikely you're going to forge forward with the aforementioned concepts and find yourself making the next engine for latest blockbuster space shooter game. As a result, Chapter Five is an overview of how to interact with physics libraries and use your Processing sketch as a facade that just queries said library for position. Box2D is the first library he tackles and with good cause — it's the same engine used by Angry Birds. And that's great because it is certainly empowering to know that if you can skin a simple game that adds a few game rules to physics, you can make a billion dollars. I learned a lot from this. I have never interacted with a physics library like this before and it was easy to produce fluid and impressive results. But it felt like glue code and it also felt like this text could be deprecated with a large update to Box2D (or it's Java and Processing equivalents). This really is a necessary and helpful chapter for this book but I felt sad that we had so quickly given up on rolling our own physics library. After Box2D, Shiffman presents VerletPhysics and provides a helpful resource for when you should use one over the other. Also, the terms for interacting with the libraries are slightly different but represent the same concept (side note: I wasn't a big fan of the convoluted names these two libraries used to designate objects and object types).
Chapter Six shows the reader how to emulate an autonomous agent by introducing "desired" vectors to each object. In this case it is a race car trying to reach a target. As the object moves, the desired vector is a updated. Examples of code are provided that show the object overshooting its target and Shiffman progresses on his path of slightly improving it by algorithmically adjusting the desired vector by introducing a slowing magnitude upon approach of the target. The actions of the object become more complicated as a flow field is suggested instead for behavior. The author explores path following and how to introduce a bit of wandering around straight line like an ant following a pheromone trail or a person walking along a wall. Simple examples of group behavior like even spacing in a crowded group or flocking in a sparse population within a large space. Lastly this chapter covers a very important aspect of code: performance. By now the reader has seen many examples where code can run slowly and this chapter's continual pairwise updating of all objects on the screen brings up Big O Notation. I wish Shiffman would spend more time on this or at least provide a separate box with more technical information on it like he did with other concepts.
The seventh chapter takes an interesting turn into cellular automata. While an interesting chapter and an interesting concept, it feels a bit disjoint from the rest of the text. While there is a way to tie it back into the long running ecosystem project. The most important aspect of cellular automata is that they are fun visualizations where as other concepts in programming that revolve around mutating state might not be as readily visible (like finite state machines or Markov models). This is the first chapter that feels a little rushed and more like a brief foray into a potentially deep field. The Game of Life is covered but only in its simplest aspects and I feel like this chapter could be better.
Chapter Eight dives into fractals. Again, like the last chapter, it is a bit short but I enjoyed this chapter. They are a great visual way to introduce newcomers to recursion and get them excited about it. On top of that, Shiffman shows how fractals appear in nature. Koch curves and Sierpinski triangles as fractal visualizations. Shiffman has a great informational box discussing the "monster" curve and tantalizes the reader with the paradox that an infinite recursion of the Koch curve results in an infinitely long line in a finite area of paper. This sort of stuff is what makes reading a book like this enjoyable and drives people to delve deeper into this concepts. I only wish the book had more of this. Also crucial to recursion in this chapter is a processing feature new to me: pushMatrix() and popMatrix(). As these are built out into trees, the author moves on to L-systems as devised by Aristid Lindenmayer. It's amazing how this simple grammar could result in a simulation of an algal growth.
The ninth chapter helps the user through a high level overview of genetic algorithms. I think one thing this book lacks is caution or warning about jumping into concepts or using concepts just because they sound cool. While genetic algorithms sound cool and futuristic, I have rarely found them to be at all useful on a professional level. Shiffman does a great job of explaining precisely how selection is determined by defining the constraints of the environment as well as the evaluation function. Unfortunately I find that these things are often hard to define and it's warnings like these that the text lacks. Nevertheless, there are a few good examples picked out for coding — unsurprisingly they use the laws of physics we just discussed and a number of computable variables for valuation. The best example is the rocket ship which is introduced after the standard monkeys trying to type the works of Shakespeare at a typewriter. Shiffman does a great job of explaining genetic algorithms and it's certainly a neat topic that's fun to think about but I'm not sure it's a good practical fundamental aspect of coding. It definitely works for the simulation side of coding so it should stay in the book but again it feels rushed with a lot of the simulation application left to the reader in the ecosystem project. I think that a much longer chapter that models predation — like wolves and rabbits — might work a lot better. You could even tie in a little bit of math and show situations where not enough mutations cause the hunter or prey to settle in on local maximums.
The tenth and final chapter briefly covers neural networks. Again, this chapter felt rushed and was missing a lot of the great explanations that were present in the first half of the book. The scant thirty five pages covers peceptrons, neural networks, training vehicles with them and even backpropagation of multilayered neural networks to hand more complex classification demands. In an effort to give this chapter some fun visualizations, the last thing Shiffman covers is the animation of the operation of a neural network. I'm intimately familiar with all these topics but the pace at which this chapter moves might be too much for a starting developer. I feel like there's a huge opportunity in this chapter to more thoroughly explain neural networks and to get readers more excited about classification systems in code.
All in all, the book was thoroughly enjoyable and I really enjoy that it is a creative commons work with both a github for the source code and the raw book. Although the latter chapters could use a lot of additional work this book is a great beginning tool for people who wish to start modeling nature in visualizations quickly and easily.
You can purchase a physical copy of The Nature of Code from amazon.com or you can name your price on a PDF directly. Slashdot welcomes readers' book reviews — to see your own review here, read the book review guidelines, then visit the submission page."
Malaku lol (Score:-1)
License (Score:-1)
If I learn to code from a book that is CC-BY-NC, may I still apply my newfound skills to a commercial project?
Re:License (Score:1)
Freedom has low standards (Score:0)
What resulted is a good book (amazing by CC-BY-NC standards)
. What exactly does this mean?
Do the C-BY-NC standards say that a book has to be below a certain standard in order to be accepted for the license? Please elaborate.
Re:Freedom has low standards (Score:1)
Re:Freedom has low standards (Score:5, Insightful)
It's just a low blow at Creative Commons authors.
No, it's criticism (something I employ during a review) and you're free to actually refute it with empirical examples disproving my stated observation. If you think that you can build a tech library out of Creative Common works that meets or supersedes a library built with traditionally licensed and copyright works then good for you. At this point in time, I sadly cannot.
Is anyone else reviewing Creative Commons books on Slashdot other than me? If it's such a low blow, you're free to jump in with reviews any time you want -- I know I'd appreciate finding new books!
I am a supporter of Creative Common works. I am not, however, a raving lunatic that can't come to terms with our current reality.
Re:Freedom has low standards (Score:5, Funny)
I am not, however, a raving lunatic that can't come to terms with our current reality.
Whatever are you doing here?
Re:Freedom has low standards (Score:2)
I'm not sure that degrading generalizations really make it up to the level of being "criticism."
Perhaps you would be better served to claim that it wasn't an intended part of the review, but instead was a mistaken and clumsily worded aside. Better than to get really defensive and petty, when in fact, it was a pathetic low blow in addition to being a raving logical fallacy.
Especially considering that you're a new user on this site.
Re:Freedom has low standards (Score:0)
Especially considering that you're a new user on this site.
lol wut? Aighearach [google.com] vs eldavojohn [google.com] = 816 < 88,100
Re:Freedom has low standards (Score:0, Troll)
Freedom Has NO Standards (Score:5, Informative)
What resulted is a good book (amazing by CC-BY-NC standards)
. What exactly does this mean?
Do the C-BY-NC standards say that a book has to be below a certain standard in order to be accepted for the license? Please elaborate.
O'Reilly publishes good to great books. Pragmatic Programmers publish good to great books. But when I flip through Creative Commons titles, you can't find that kind of quality on a regular basis ... yet. I was simply trying to say that compared to everything else I've come across as Creative Commons works, this book helps raise the bar. I might even say to the point of competing with major publishers. I think I've reviewed one other CC book (Pilgrim's HTML5?) that was worth reviewing but I still have to say that an entire series like Pragmatic Programmers still outshines 99% of what you find in CC licensing. Now, that's all just my opinion because I know some people that prefer man pages over anything else. Hope that makes that clearer.
I'm the reviewer, I use my standards. Freedom means publish whatever you want, good or bad. There are no standards and that's very important.
Re:Freedom Has NO Standards (Score:5, Informative)
I agree with your characterization of what good publishers do, but I think it's more about the publisher than the license. Good publishers do: 1) vetting, so crap doesn't go out under their name; and 2) editing, both for style/substance and copyediting. Books that don't go through that process are more hit-or-miss, because literally anyone can publish them. Some of 'em are good, and some not.
But I don't really see a license-related difference between "all rights reserved" books and "creative commons" books. Most books published on Lulu are all-rights-reserved, and the average quality isn't particularly stellar. And in the other direction, CC-licensed books published by major publishers are typically on a quality par with their non-CC-licensed books, e.g. O'Reilly's Open Books [oreilly.com] series meets the regular O'Reilly standards.
Re:Freedom Has NO Standards (Score:1)
Slashdot editors apparently support this notion of "publish anything, regardless of quality." Is a glowing review from the author's (de facto) agent relevant? Who cares! Publish!
Re:Freedom Has NO Standards (Score:1)
Re:Freedom Has NO Standards (Score:2)
So, plugging some companies and then doing a poorly executed search or browse based on license somehow makes you able to compare apples to oranges? As long as it results in the right plugs, I guess.
You can find low quality commercially published books all day long, too. For example, most CS textbooks.
I would even propose that there are a larger number of low quality books for sale than available for free, and I'd also offer an explanation... because there are financial incentives to writing a book to sell, but having a genuine interest in the subject is more likely to result in a great book. So there are a lot of crappy books for sale. If you don't believe me, check a bookstore.
Re:Freedom Has NO Standards (Score:0)
So, plugging some companies and then doing a poorly executed search or browse based on license somehow makes you able to compare apples to oranges? As long as it results in the right plugs, I guess.
You can find low quality commercially published books all day long, too. For example, most CS textbooks.
I would even propose that there are a larger number of low quality books for sale than available for free, and I'd also offer an explanation... because there are financial incentives to writing a book to sell, but having a genuine interest in the subject is more likely to result in a great book. So there are a lot of crappy books for sale. If you don't believe me, check a bookstore.
So shut up and start writing reviews, how 'bout?
Re:Freedom Has NO Standards (Score:1)
No, it's criticism (something I employ during a review) and you're free to actually refute it with empirical examples...
Bold is mine. (Just for some perspective I will till you that I am the OP.)
First off I thank you for the explanation, which is something you did not do in the "article" or summary. Secondly I didn't realize it was YOU, or I wouldn't have been as cynical as I was (because you're statements do tend to be thoughtful and educated, even by Slashdot standards). Also, in answering your reply I've mixed in responses that you've made to other people (this is my mistake, but I think my points are relevant anyways). Also, I don't want to make this into a major issue. Let's face it: it's a fairly minor issue, and I'm not going to be hiring lawyers or hackers to defend against the tyranny and injustice of your opinion. Although I will be asking for financial and military support from my buddy Hugo Chavez.
First off, it seems a bit unreasonable to ask somebody to provide "empirical examples" when the argument (or question) was rhetorical in nature and based on deductive thinking. You're statement "amazing by CC-BY-NC standards" is focusing on criticizing Creative Commons, it is not criticizing the people who write (or fail to write) under a CC license, and it is not criticizing incompetent or lazy authors of CC material. The word "amazing" seems to be an appeal to emotion. Again, you are making a statement about a license rather than how mature and evolved the material that gets published under CC is. Perhaps this may have been a semantic error on your part. If it is I can only see you defending your error (so far).
For some perspective it is sometimes easier to look outwards (yes, it is analogy time!). So, like you can make a general, and somewhat orthogonal statement that it is "amazing by CC-BY-NC standards". So too can I make general and over-reaching statements that have inherent biases in them in issues of race, for example. I can state that, it is amazing even by African American standards, or it is amazing even by Muslim standards. Yes, the topic could be relevant and the statements could be generally correct, but there is still an inherent bias. To elaborate; it may be amazing that by African American standards, a certain subset of the black population has only minor criminal records and police intervention associated with them. This may be true, but there is an inherent bias in this statement just like there is an inherent bias in racial profiling.
Is anyone else reviewing Creative Commons books on Slashdot other than me? If it's such a low blow, you're free to jump in with reviews any time you want -- I know I'd appreciate finding new books!
Just because I am lazy does not mean my arguments are untrue (this, to remind you, is an ad homonim argument on your part, though you try to sneak it in as self-congratulatory jibe. OK, on looking back, you were not responding to me, but still it's not a response that is based in logic and objectivity. You should be doing this free work because of the love of knowledge and pedagogy, and not because of what some random Slashdot reader has to say.
You also said:
I am not, however, a raving lunatic that can't come to terms with our current reality.
Again, you are making general statements without backing them up. Backing them up later when people question your comments (or sanity) does not count, because the criticism in general is related to the original post. Since you believe that "empirical observations" are important, then I think it would be only fair for you to post a copy of your medical and psychiatric history. We, as Slashdot readers, will then have a better understanding of how to judge your comments based on your psychiatric profile. Thanks in advance.
Of course, you can choose to completely ignore my thoughtful and insightful analysis of your opinion. And I of course, can choose to use the political and military support of Hugo Chavez to back up my opinions.
(Not to get lost here.). You said:
Hope that makes that clearer.
Yeah. Thanks.
How Did the Parent Get Modded Up? (Score:0)
Re:Freedom has low standards (Score:3)
I've found the "best" stuff is released under CC-NC-ND not just CC-NC. Its actually kinda hard to find CC-NC good or bad.
Under CC-NC-ND you've got doctorow's novels, and TED talks, afaik. MIT OCW videos are not CC at all, but have their own MIT license that is not too conceptually far away from CC-NC-ND (I am not a lawyer, although any fool can see they're conceptually close and can also see they're not literally the same license terms)
Re:Freedom has low standards (Score:1)
What resulted is a good book (amazing by CC-BY-NC standards)
. What exactly does this mean?
Do the C-BY-NC standards say that a book has to be below a certain standard in order to be accepted for the license? Please elaborate.
Think of the way these things typically go. You are writing a book. You have two options to put it out. You could A) use a major/established publisher, who will be sure to pay you a decent chunk of change, but will likely publish it under standard, restrictive terms B) release it under C-BY-NC, probably by self-publishing it, where income and notoriety is likely to be iffy, at best.
For a host of reasons, most people would probably like to use A), the only "problem" is that the major publisher has editors and quality control, and tries to avoid letting crud through path A). So if your book is crud (and remember, 90% of everything is crud), you're left publishing it though B). So even if the major publishers are marginal in their crud detectors, and let's say they might let through 5% (of total) crud and 5% good stuff. They're only 50% (5/10) decent, but that's still better than the 5.6% (5/90) decent from the self-published C-BY-NC group.
The problem with C-BY-NC is not an affirmative enforcement of a lower standard, but a comparative lack of enforcement of a higher standard.
But again, that's generalizing. It's slightly unfair to criticize a particular (this book) for the properties of the general (C-BY-NC licensed books), but it does work as a decent heuristic, as long as you have methods (like reviewers pointing out the particular's quality) which can work around the exceptions to the rule.
Wow (Score:2)
Successful Troll wins!
Pay what you want (Score:0)
This book is available for pay what you want, I like to support this kind of behaviour.
I paid $1. I might not even read this book, but I hope this encourages more authors to do the same - and open up their works for the general public.
If I like the book, I'll go order a few more copies for my academic friends - this time with a higher price tag.
Re:Pay what you want (Score:2)
Re:Pay what you want (Score:2)
A quick look at the HTML site and I'd like to say it looks pretty non-soporific. Kudos. I think that may be the standard eldavojohn referred to in the summary.
Tex and ASCIIDOC (Score:2)
When I saw "book source", latex was expected.
(As I am incompetent artist, I seek latex book sources to take something consistent for my projects)
No, it is done in ASCIIDOC - yet another book making program.
While TeX and LaTeX are old, they are still excellent tools for the job.
What makes alternatives better? What can not be done properly by TeX?
BR
s52d
Re:Tex and ASCIIDOC (Score:3, Interesting)
How much of this drek... (Score:2)
...do I have to read before I have any idea what the book is about? Crappiest book review ever. Is the book of similar caliber?
Re:How much of this drek... (Score:0)
I've scummed through the book. No you can easily get an idea what the book is about by reading the first chapter. It's more or less an introduction to CS.
yWoot! fp (Score:-1)
Exercises (Score:2)
Re: Exercises (Score:1)
Re:Exercises (Score:2)
And I really like it. Problems really help in terms of practical learning (as opposed to foundational learning, which I consider reading to be) and retention, at least for me.
I also use previous Top Code competition problems to hone my algorithm skills, but I don't compete.
Java and Processing developers? (Score:0)
What are Java and Processing developers?
Re:Java and Processing developers? (Score:2)
Processing is an open-source language. The article assumes you knew this common verb, especially common in programming, was also a noun and the name of a language.
Re:Java and Processing developers? (Score:2)
I can't decide which is less informative: the book's title, or the article summary here.
Re:Java and Processing developers? (Score:0)
I wonder why they didn't use a hyperlink in the summary to highlight this is an obscure programming language instead of a usual word. I've never heard of it before.
http://processing.org/
"Processing is an open source programming language and environment for people who want to create images, animations, and interactions."
They need a better name. If I could figure out what it does, I'd suggest one...
Re:Java and Processing developers? (Score:2)
It was worth scrolling all this way to learn something new. Thanks!