lohahz.blogg.se

Ecto changeset
Ecto changeset










ecto changeset
  1. Ecto changeset software#
  2. Ecto changeset code#

When our code is easy to change, we can respond to changing requirements quickly, thereby providing more value to our clients. Since "well-designed" is a fairly nebulous term, I'll lean on to provide a definition.įrom a practical point of view, changeability is the only design metric that matters code that’s easy to change is well-designed.

ecto changeset

In trying to meet both of them, it helps to focus on building well-designed applications. Thankfully, these goals are not mutually exclusive.

ecto changeset

Ecto changeset software#

As engineers, our desire is to build software that is a joy to work on. This post at least provides a line in the sand that I can revisit as I build up more experience in using and observing changesets in the wild.How Elixir's Ecto Promotes Well-Designed ApplicationsĪs consultants, our job is to provide the most value possible to our clients over the course of our engagement. It feels like it has been caught between two opposing principles and has thus been pulled in two different directions.Ĭhangesets want to offer welcome convenience in building web applications and they want to follow the Elixir and Phoenix principles of separation of concerns and decoupled code. It doesn’t decompose as neatly as I might like. My gut feel is that although this represents an improvement on the coupling of ActiveRecord, it feels like it didn’t go far enough.Ĭhangesets don’t seem to comply with the Single Responsibility Principle, the first of the SOLID guidelines.and the higher-level encoding of the overall process or flow of data through the application from request to repository. It feels in a way that a changeset is trying to operate on two different levels: the low-level change tracking, validating, etc.Changesets are responsible for casting, filtering, validating, change tracking, and receiving feedback from the data repository.While changesets have been successfully decoupled from forms on the one side and queries on the other there remains evidence of a previous coupling: action, repo, repo_opts, constraints.It could be that there’s something to be improved here, despite how embedded changesets in the mindset of a Phoenix developer. It could be simply that this is a thorny problem to solve and dealing with different responsibilities is simply a fact of life. This could of course be down to my lack of experience and the resultant failure to fully appreciate the abstraction.

ecto changeset

With changesets on the other hand I’m a seeing a forest because of all the trees. Ecto.Query is a beautiful, thin layer of abstraction over SQL. Plug offers a very elegant way of handling the request-response cycle. In other parts of Phoenix this clean separation of responsibilities can be clearly seen. One of the claims is that ‘Rails is not your application’ with Phoenix building on this Clean Architecture mantra by separating out lib and web folders and functionality, introducing contexts, and encouraging a more decoupled application design.Ĭhangesets therefore provide an interesting litmus test of this philosophy. In addition of course to the introduction of a programming model that fits hand in glove with the requirements of the web ( Phoenix.PubSub, Phoenix.Presence, Phoenix.LiveView). Phoenix is a framework which supposedly learns from the limitations of Rails to bring something that is explicit (over Rails’ implicitness), straightforward (over Rails’ indirection) and simple (over Rails’ complexity). Indeed if we trace the heritage of Elixir in general and Phoenix in particular then there is a strong current of being better across a chosen set of criteria.Įlixir borrows Ruby’s friendly syntax but inhabits a world of performance, concurrency and fault tolerance which Ruby finds difficult to match. Certainly these are all united by the goal of preparing, controlling and executing a set of changes but I can’t help but get the feeling that it is doing too much.ĭoing too much was always a criticism of ActiveRecord in Ruby on Rails. The first thing that strikes me about this is that a changeset is responsible for several different things. So far in What is a Changeset? and Validations we have seen how an Ecto Changeset is an immutable data structure which is transformed by applying different kinds of functions for different purposes.












Ecto changeset