I’ve got a new book out which shows you how to do the Toy Robot exercise in Elixir:
The first 6 chapters of the book cover how to solve the common part of the exercise. Chapter 7 (coming soon) covers processes and supervision trees while building the foundations of a multiplayer Toy Robot game. Chapter 8 will finish that game.
I view this book as a “sequel” to things like Joy of Elixir, the getting started docs for Elixir or Elixir School. It’s a real (enough) project with real problems and I hope people enjoy reading it and following along.
Let me know what you think in this thread!
Table of Contents
Introduction
Introducing the Toy Robot
Simplifying the problem
Creating the application
The MOVE command
Moving west
Moving north and south
Moving in the right direction
Turn left!
Turn right!
Catching bugs
Finding the bugs within
Regression testing the turn_right function
Regression testing the move function
Regression testing the move_west function
Regression testing the move_north and move_south functions
Thank you very much, so far it’s been an enjoyable read! I spotted some (few) typos, though. Do you have something like an issue tracker?
On a side note: Could you provide some insight into your workflow for creating the book? Did you use the Leanpub markdown right from the start or was there additional tooling?
No issue tracker so to speak, but if you email me (me@ryanbigg.com) with the page number where you found the mistakes and a bit of context around them, I should be able to fix them up quick smart!
Here’s a short version of the workflow of writing the book:
Write in an ERB (Embedded Ruby) version of Leanpub’s Markdown
Run my ERB parser script to convert my ERB into Leanpub’s Markdown
Push it up to GitHub (for version control)
Manually copy the files over to a Dropbox folder that Leanpub shares with me
(Optionally) Check the “Notify readers of an update”
Hit “Publish”
The ERB part of the process exists because there’s some fiddly Leanpub-specific syntax that I can automate away with some pretty basic Ruby. (This part is not written in Elixir yet because I wrote it back when I only knew Ruby )
Another thing is that I use VS Code’s file-shortcuts.code-snippets file to have tab-complete for common code blocks within my books. I configure it like this:
{
"Code block for robot.ex file": {
"prefix": "robot.ex",
"body": [
"<% elixir title: \"lib/toy_robot/robot.ex\" do %>",
" $1",
"<% end %>"
],
"description": "Code block for robot.ex file"
},
Then I can type ro.ex and hit <Tab> and it will fill it out to be:
<% elixir title: "lib/toy_robot/robot.ex" do %>
[cursor goes here]
<% end %>
Then if I put in code in that box and hit <Tab> again, it will jump to the end of it. That speeds up writing a bit!\
Thanks for the elaboration. Cool idea to abstract away fiddly syntax with ERB. Did you use any tools to render your book locally (without pushing to Leanpub)?
I’ve covered all the content I set out to cover in this book, and so now we’ve got plenty of words covering:
How to build an Elixir project from scratch
Doctests
ExUnit tests
GenServers
Supervisors
Registries
It’s a smidge over 60,000 words, and about 220 pages.
I’m going to spend this next week reading through it myself and making sure everything is as correct as it can be and then I would say this book is done!