Oh dear. After telling myself I wouldn’t I somehow managed to lunch out my Seven Languages in Seven Weeks oddyssey for 6 months. I had been most of the way through the Elixir section and then got distracted by a shiny object or something.
Well, today I am back on the wagon and the way I am going to play it is to wrap up Elixir quite quickly and move on to Julia. I will certanly come back to Elixir in the future. I like its combination of Scheme-like simplicity, Ruby-like syntactic beauty and Erlang concurrency. But the intervening 6 months have made me lose my train of thought somewhat.
FWIW I had made a start at the exercises back in April, so I have tidied them up and pushed them to github now. I had not however attempted the hard exercise. I think I will leave that for another day too.
Exercises
Easy Exercises
How can you crash your server? What happens if you crash it with and without a supervisor?
Second question first. With a supervisor, my server ought to get restarted after a crash. Unless the crash is a really exciting one — caused by an overheating CPU or something like that!
On how I might cause a crash, apart from inducing hardware failures, the most likely problem at a software level is discussed in the text — passing data that the server doesn’t understand. For example calling an unknown function will do it.
Add a timeout to the pitcher or catcher? What happens when you time out?
Here is what I had written.
def glove do
receive do
{:pitch, pitcher} -> send pitcher, {:catch, self()}
after
2000 -> IO.puts "Oh crap. Went to sleep."
end
end
Medium Exercises
Write tests for the OTP database
You can find my tests in the tests folder on github. What I will say is that mix makes the whole process of writing tests relatively painless. It works very nicely and is great to have as such a core part of the language.
Hard Exercises
Not attempted