#Submitting Answers to Exercises for Nature of Code 2 Book

16 messages · Page 1 of 1 (latest)

viscid heron
#

In the Introduction it states:

Solutions for the exercises are provided on the book’s website. Or I should say, I aspire to include solutions for all the exercises on the book’s website. As of this moment, just a handful are available, but hopefully by the time you’re reading this, there will be many more. If you’d like to contribute a solution to an exercise, I would love for you to do so via the book’s GitHub repository!

I'm wondering which repo to submit a pull-request to:

The noc-examples-p5.js repo appears to only have the Examples which makes sense considering title of repo.

The other place I could find was in the noc-book-2 repo in noc-book-2/content/examples

There is 1 exercise solution in the 00_randomness folder. I'm thinkin this is the place to submit solutions to exercises but wanted to check here first.

GitHub

Port to p5.js of Nature of Code examples. Contribute to nature-of-code/noc-examples-p5.js development by creating an account on GitHub.

GitHub

Nature of Code with p5.js and Notion workflow / build system. - nature-of-code/noc-book-2

Over a decade ago, I self-published The Nature of Code, an online resource and print book exploring the unpredictable evolutionary and emergent proper

cedar pollen
#

seems like it should be noc-book-2, @open canopy could you confirm? (also, is it intentional that exercise solutions aren't currently on the site?)

viscid heron
#

While I wait for confirmation, think I'll take a spin through my new book that came in the mail today! I haven't bought a real book in a very long time and I'm turning the pages like it's an ancient manuscript that might dematerialize between my fingers at any moment. What a beautiful design! The book is well made - I love the feel of it, and amazingly, though it's brand-spanking new, it's somehow staying open to page 4 without my using a paper-weight on one side. Some strange and beautiful physics at work here 😉

viscid heron
#

@cedar pollen Maybe this isn't a big deal to the author but thought I'd mention it. Also note that this could be a one-off situation on the first example - I haven't checked them all.

In the book (website and print) the author explains a few coding conventions.

As I understand it he'll be using let for variables and === to ensure strict equality.

He mentions 3 places to find the code examples, but only one of them follows the coding conventions (website book).

The file on the p5 online editor and in the Examples github repos (both, see previous post), he uses const and ==.

Again, how important this inconsistency is I don't know - but if you all like, I can track them as I'm going through the book and note any others I might find, or just do them in github.

Here we are: the beginning. If it’s been a while since you’ve programmed in JavaScript (or done any math, for that matter), this chapter will reacquai

Over a decade ago, I self-published The Nature of Code, an online resource and print book exploring the unpredictable evolutionary and emergent proper

mint valve
#

Note that the convention is for the book, not necessarily for the examples in other places.

const over let is actually a good practice. In short, const means you cannot reassign a variable:

let x = 1;
x = 2;
// ^This is valid

const y = 1;
y = 2;
// ^This will throw an error

Depending on who's "best practices" you're following, you should use const whenever possible, and only use let when needed.

What you should not be using is var. It was the way to declare variables before we had let and const, and has some slightly different behavior that makes it no longer recommended.

As for the == over ===, in that example I'm assuming it's just a small oversight. I myself did a lot of little mistakes like that at work. Perhaps it's a good topic for a possible Coding Train video about linters in the future

open canopy
#

Hey!! Thank you for your patience here! @viscid heron really appreciate you starting this thread. This is a classic case of "I wrote something in the book thinking I had all the time in the world to get a system set up for it before the release and then never got around to it!" But now is the perfect time for me to figure this out and make a plan....

#

Some info and thoughts

#

This noc-examples-p5.js repo is essentially deprecated, the "ground truth" for the examples i the p5.js web editor and everything listed on the examples page on the website.

#

So step 1 would be add info to the README for the noc-examples repo and archive it. Would gladly accept any help with this!

#

This is, in fact, the correct place for the examples: nature-of-code/noc-book-2/tree/main/content/examples

#

So it would probably make sense to create nature-of-code/noc-book-2/tree/main/content/exercises, however, the way the repo works is that everything in content created through API calls to Notion and the p5.js web editor. So long story short, maybe I could set up a special repo or system for people to submit exercise solutions then I would manually create the Notion page and p5.js web editor versions and build this page on the website

#

@viscid heron in terms of the const and === inconsistencies if you want to open a github issue and keep a list there of where you find the inconsistencies that would be a helpful way to track!

viscid heron
#

@open canopy all of the above ⬆️ understood. Will head over to the discussion link.
Though I've used git and git/hub for years on my own, I'm a newbie when it comes to using the tool to collaborate on a project. Perfect time to learn!

open canopy
#

Ok, I archived the old repo now! We can start working on getting the exercise solutions into the book's website.