Hacker News new | past | comments | ask | show | jobs | submit login

> [summary of the book: write as much as you possibly can in pure functional code, mostly because it's so easy to test. Then use GenServers (etc.) at the boundary to hold the state at the top of your stack of pure code]

In my experience this is a good idea in pretty much any language, see also https://www.destroyallsoftware.com/screencasts/catalog/funct...






Indeed - that is the exact architecture that the book is talking you through. It maps it well on to the specific tools you have available in Elixir. Unsurprisingly, Elixir is an extremely good fit for this architecture.

What is it that makes Elixir such a good fit? (I don't know much about Elixir.)

It's a functional language with all the usual bits that entails, so writing pure code is right in its wheelhouse. It's a pragmatic, dynamic language, so very much an easy on-ramp to functional programming. The testing library (ExUnit) is good too, so with pattern matching testing is a joy.

Where it really stands out is the runtime model. You can spin up as many GenServers as you want to hold and update state - they're like goroutines so they're very cheap and you can have thousands. They're a great way to handle state as you just handle incoming messages one after the other and change your state appropriately. Then you arrange them with supervisors so that if one does something unexpected it's restarted and going again.


Thanks!



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: