![]() ![]() ![]() You instead create a namespace for each group of data:Īnd in your data file `lib/blog_app/blog/post.ex` for example, you'd keep just your schema defining the fields like "title,, body, etc" and code to handle validations and virtual attributes. Instead of having User, Session, Post, and Comment models which contains your DB schema, business logic, and interfaces for getting/setting data all models directory ala Rails: The `data` files (aka your new models) are basically where the schema for your model lives and the `context` (your models API) is the interface for your data. I recently ported my app from 1.2->1.3 and moving away from Models to Contexts/Data was a simple transition that makes a lot of sense. The directory reorganization is a good sign that Elixir/Phoenix are not simply rehashing Ruby/Rails for the sake of popularity but are willing to prioritize what makes the most sense for this particular language - and asking how they can improve upon what already exists. It makes code so much more readable and maintainable in my opinion. So Elixir has this "with" feature that looks sort of like this:ĭef create(conn, %) do Any of those checks might cause it to exit early or to switch paths. until finally you're function is ready to actually perform its purpose. Usually you might have code that sets a variable from something, checks to make sure it's valid, sets another variable, checks to make sure it's valid, etc, etc. This is fantastic, it's one of my favorite things now. That's basically the equivalent of having a single say() function that then does a switch/case on the input.Īnd a more recent addition to the language is "with". This is one of my favorite things though you can destructure things, you can pattern match inside a function using case, and you can pattern match on functions themselves like:ĭef say(_msg), do: IO.puts("Where am I?") Other languages have this too, so it's not like this is unique. Pattern matching is beautiful and it's easy to use. Nothing else really has this kind of thing. It's like having micro-microservices running inside your virtual machine. but I'll list some things I like about Elixir:Įrlang's concurrency model is amazing. I wouldn't say I like things over C#/.NET (I love C# and use it for mobile/desktop devel, but I've never used it for web). Although Shankar has already made an announcement with the intention to update the book soon after the officially 1.3.0 release. I should note that the current version of the book is targeting Phoenix v1.3.0-rc.2. If you have previous experience in another MVC framework and are interested in Phoenix I highly recommend this series (at least based on what I've read so far). This was perfect for what I needed and it was reassuring knowing exactly how much (or little) Elixir you need to know before diving into Phoenix. What Shankar has done is to dedicate one chapter to teach just enough Elixir for you to get started. I didn't want to make the mistake of trying to learn Rails before being comfortable with Ruby again so I put off on learning Phoenix altogether. I have previously tried to study Elixir a few times with the intention of eventually getting into Phoenix but I always got overwhelmed by the OTP material. The most important thing for me though, is how Shankar condensed teaching Elixir into a single chapter. I also appreciate the TDD approach including both acceptance and unit testing. The book is full of interesting tidbits and explanations about Phoenix internals without getting in the way. Going through the book feels like sitting next to a colleague, who is introducing you to Phoenix and is really knowledgeable in the topic. ![]() What I can say so far is that the author's approach resonates really well with me. I just got it a few days ago and I'm about 30% into the first book. Another great resource that was recently released is the Phoenix Inside Out series by Shankar: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |