[0] https://elixir-lang.org/getting-started/pattern-matching.htm...
[1] https://elixirschool.com/en/lessons/basics/pipe-operator/
[2] https://elixir-lang.org/getting-started/meta/macros.html
[0] https://elixir-lang.org/getting-started/pattern-matching.htm...
[1] https://elixirschool.com/en/lessons/basics/pipe-operator/
[2] https://elixir-lang.org/getting-started/meta/macros.html
Especially for a dynamic language which uses tuples/maps for a lot of arguments.
Imo this is actually much better than an orm because it really hits home that the data in memory are stale as soon as you receive them because database transactions are explicit, and not hidden behind getters and setters.
ORMs can get you into trouble because they try really hard to hide the problem of distributed state and sources of truth.
It has this cute macro-based syntax, and that seems to inform even the "functional" API as well. Yet when you I wanted to do something just a bit more advanced like joining on an association whose name I don't know in advance (or, say, want to parameterize the function with), I had to resort to writing a macro myself and then eval-ing it an runtime.
Well, take the numerous articles extolling the virtues of Sequel, or DataMapper, or, related to the current discussion, Ecto itself. Like how expressive this stuff is. And how ActiveRecord creates a too huge API surface on models, and that that leads to bad design, etcetera. Now to mention the callbacks, which are admittedly problematic.
But then I try those aforementioned libs and see sharp corners like terrible argument validations (in case of Sequel) which lead to silently failing code, or actual hard limitations on what I can ask Ecto to do without resorting to meta-programming.
> I also haven't ever found a good replacement for AR migrations
IME, both Sequel and Ecto migrations are fairly serviceable. But neither provides the schema dumping feature that AR has. Which is pretty handy.
The first part is your schema. It defines an Elixir struct that is your domain model of your data.
The second idea/part is the concept of a changeset. It represents a change you'd like to make to the data store, but haven't yet. These are composable, so you can bundle a bunch of changes into a single, atomic unit, which you then send to your repo. If any part fails, then the whole thing fails, no changes are made to the persisted data.
The last thing is migrations, which strictly speaking are optional, but a huge convience. They define how you'd like your database to be structured. The cool thing about them is that they define rollback operations automatically.
Once Ecto "clicks", it really becomes a strong selling point to the language as a whole. It makes working with persisted data super easy.
Quite a few of my students have said great things about Phoenix in Action, from Manning, and it looks to me like a fantastic resource for beginners. Elixir in Action is also top-notch and will show you what's special about the BEAM.
Great book though.
The auth generator is just a new feature. Learning how the pieces work from the book is still worthwhile.
My advice if you want to avoid confusion as you're learning is to just use the same version of Phoenix the book does! (1.4 in this case)
After you go through it, you can follow the official upgrade guides in just a few minutes.
I liked the book Programming Elixir 1.6 By (Pragmatic) Dave Thomas. Solved the exercises. Did not quite find use for macros. And I have not done any production projects.
The pragmatic studio has some courses for the space: elixir, OTP, LiveView, etc. and free tutorials. The quality is good. Simon Thomson's course on futurelearn was also good. https://pragmaticstudio.com/ and https://www.futurelearn.com/
A recurrent problem for me though has been to write an application. I used to write java's petclinic/petstore application when learning a framework, library, etc. Have not been able to do so with some other ecosystems... perhaps laziness, perhaps have not been able to answer why. And languages in isolation have not clicked for me much apart from maybe making me think in different ways.
Why does this Erlang/Elixir/BEAM interest me then? A colleague who talked highly of it... Then there's Joe, his talks, and Alan Kay's recommendation has Joe's thesis on recommended reading list: https://news.ycombinator.com/item?id=20653453
There is also Erlang Masterclass series 1,2,3 starting here: https://www.youtube.com/playlist?list=PLR812eVbehlwEArT3Bv3U...