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."
Re: (Score:1)
Re: (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: (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.
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: (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: (Score:1)
Re: (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,
Re: (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). A
Re: (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: (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 an
Wow (Score:2)
Successful Troll wins!
Re: (Score:2)
Re: (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: (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?
Exercises (Score:2)
Re: Exercises (Score:1)
Re: (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.
Re: (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: (Score:2)
I can't decide which is less informative: the book's title, or the article summary here.
Re: (Score:2)
It was worth scrolling all this way to learn something new. Thanks!