Название: Toy Robot - The Elixir Version Автор: Ryan Bigg Издательство: Leanpub Год: 2021-01-18 Страниц: 224 Язык: английский Формат: pdf (true), mobi, epub Размер: 10.2 MB
The Toy Robot is a common interview exercise for new programmers. This short book will take you through how to implement it in Elixir in a BDD-style, with some great explanations and imagery along the way.
The Toy Robot exercise was originally developed by Jon Eaves. He explains why he did it in this blog post. If you're a new Elixir developer who's gone through some basic Elixir tutorials and you're looking for the next thing to build your skills, this book is a great start. It covers the Toy Robot exercise from start to finish, testing with Elixir features such as ExUnit and Doctests along the way. The Toy Robot exercise is commonly used in interviews as the ways to solve it in any language are not as simple as they first may seem. This book covers one implementation of this exercise in Elixir. It is not intended to be the most perfect implementation of the Toy Robot exercise possible, but instead is my personal take on it.
In this book, I’m going to go through how I would implement the Toy Robot exercise myself in Elixir, just for demonstration purposes. I’ll be building it up piece-by-piece with the overall aim to be to help anyone reading how to think through and implement this problem. This book is not intended to be the ultimate 100% perfect and make people weep with joy at the elegance of the solution type of deal. It is my approach to the Toy Robot problem and I’m sharing it with you in the hope you may gain something from it. There may, nay, WILL be better ways to write what I have written here. It is up to you find out what they are. (And then to tell me so that I too may learn!)
This version focusses on Elixir and its testing framework, ExUnit. In this book, I’ll be assuming that you have a base-level of Elixir knowledge. If you’ve gone through my other Elixir book, Joy of Elixir, you’ll have the right amount of knowledge. You’ll know about lists, maps, functions, and modules. All things that we’ll use a lot of in this book. Consider this Toy Robot book a spiritual sequel to Joy of Elixir. If you haven’t gone through that book but have learned Elixir elsewhere, then I would expect you to have done enough reading about Elixir to know your modules from your functions, as well as lists and maps too. I am also going to assume a base-level understanding of test-driven design.
In this book, I demonstrate best practices for developing a small Mix application that can solve the Toy Robot exercise. Along the way, you'll learn аbout:
How to break a complex problem down into small, approachable chunks When to use Doctests or regular ExUnit tests Tradeoffs between different ways of pattern matching How to work with Elixir processes using GenServer + DynamicSupervisor
The Toy What Now? The Toy Robot! It's a very common interview exercise given to new programmers. Here's the variant of the problem's description that we use in the book:
The application is a simulation of a toy robot moving on a square tabletop, of dimensions 5 units x 5 units. There are no other obstructions on the table surface. The robot is free to roam around the surface of the table. Any movement that would result in the robot falling from the table is prevented, however further valid movement commands are still allowed.
The application reads a file using a name passed in the command line, the following commands are valid:
PLACE X,Y,F MOVE LEFT RIGHT REPORT
Here's some rules for these commands:
PLACE will put the toy robot on the table in position X,Y and facing NORTH, SOUTH, EAST or WEST. The origin (0,0) is the SOUTH WEST most corner. All commands are ignored until a valid PLACE is made. MOVE will move the toy robot one unit forward in the direction it is currently facing. LEFT and RIGHT rotates the robot 90 degrees in the specified direction without changing the position of the robot. REPORT announces the X,Y and F of the robot.
The file is assumed to have ASCII encoding. It is assumed that the PLACE command has only one space, that is PLACE 1, 2, NORTH is an invalid command. All commands must be in upcase, all lower and mixed case commands will be ignored.
Внимание
Уважаемый посетитель, Вы зашли на сайт как незарегистрированный пользователь.
Мы рекомендуем Вам зарегистрироваться либо войти на сайт под своим именем.
Информация
Посетители, находящиеся в группе Гости, не могут оставлять комментарии к данной публикации.