Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Image

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.
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.
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.

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."

*

This discussion has been archived. No new comments can be posted.

Book Review: The Nature of Code

Comments Filter:
  • by Anonymous Coward on Wednesday January 09, 2013 @04:15PM (#42537707)
    -A- is shit.
  • by Anonymous Coward on Wednesday January 09, 2013 @04:17PM (#42537743)

    If I learn to code from a book that is CC-BY-NC, may I still apply my newfound skills to a commercial project?

  • by Anonymous Coward on Wednesday January 09, 2013 @04:25PM (#42537865)

    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.

    • by masternerdguy ( 2468142 ) on Wednesday January 09, 2013 @04:28PM (#42537905)
      It's just a low blow at Creative Commons authors.
    • by eldavojohn ( 898314 ) * <eldavojohn@gm a i l . com> on Wednesday January 09, 2013 @04:34PM (#42537989) Journal

      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.

      • by Trepidity ( 597 ) <{delirium-slashdot} {at} {hackish.org}> on Wednesday January 09, 2013 @04:55PM (#42538267)

        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.

      • by Garridan ( 597129 ) on Wednesday January 09, 2013 @04:56PM (#42538287)

        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!

      • by Aighearach ( 97333 ) on Wednesday January 09, 2013 @05:26PM (#42538797)

        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.

        • by Anonymous Coward on Wednesday January 09, 2013 @05:28PM (#42538841)

          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?

      • by Anonymous Coward on Wednesday January 09, 2013 @07:37PM (#42540549)

        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.

    • by vlm ( 69642 ) on Wednesday January 09, 2013 @05:08PM (#42538457)

      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)

    • by Anonymous Coward on Wednesday January 09, 2013 @05:09PM (#42538483)

      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.

    • by hoboroadie ( 1726896 ) on Thursday January 10, 2013 @09:26AM (#42545287)

      Successful Troll wins!

  • by Anonymous Coward on Wednesday January 09, 2013 @04:58PM (#42538295)

    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.

  • by s52d ( 1049172 ) on Wednesday January 09, 2013 @05:06PM (#42538423)

    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)

      by dshiffman ( 2812203 ) on Wednesday January 09, 2013 @09:37PM (#42541623)
      ASCIIDOC was a somewhat arbitrary choice. The goal for this project was to be able to easily generate the book in a variety of formats. Since ASCIIDOC can parse into HTML rather easily, I was then able to generate a web version of the book, a PDF for print, and ultimately I hope to be able to generate ePub and Mobi as well. LateX is a fantastic tool as well.
  • by anyaristow ( 1448609 ) on Wednesday January 09, 2013 @05:54PM (#42539321)

    ...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?

  • by Anonymous Coward on Wednesday January 09, 2013 @06:40PM (#42539971)
  • by CockMonster ( 886033 ) on Wednesday January 09, 2013 @06:43PM (#42539999)
    I really hate buying books about a topic and then it having exercises for me to figure stuff out I bought the book for. Not everybody is a student. At least Knuth gives the answers in his books.
  • by Anonymous Coward on Thursday January 10, 2013 @06:37AM (#42544195)

    What are Java and Processing developers?

When your work speaks for itself, don't interrupt. -- Henry J. Kaiser

Working...