This is a weird one to me. I really dislike the magical way Django does this and I'm glad Ecto doesn't. It also allows you to have separate Ecto structs representing different parts of a table in scenarios where that is desirable.
ElixirNitpicks
11–20 of 60 posts
Re: ElixirNitpicks
#12For me it would be the Pin-Operator. Which is only needed cause variables can "mutate". IMHO it's not that common that we need to "reassign" variables, we could life without the looks-like-reassignment. I touched Erlang before, it's hard to get my brain to accept elixir is different in regards of variables :)
Re: ElixirNitpicks
#13For me it would be the Pin-Operator. Which is only needed cause variables can "mutate". IMHO it's not that common that we need to "reassign" variables, we could life without the looks-like-reassignment. I touched Erlang before, it's hard to get my brain to accept elixir is different in regards of variables :)
Re: ElixirNitpicks
#14Interestingly, though I am not a great Rust programmer, nor a great Elixir programmer (I have written programs in both languages). And, gotten a little ways through the amazing Exercism ( https://exercism.org/tracks/elixir ). What I loved about this writeup was the way I could review both by comparing two languages in which I have a moderate understanding. The comparison of imports was very engaging to my brain. I re…
Re: ElixirNitpicks
#15 with {:is_email, true}
{:error, :bad_request}
{:is_available, false} ->
{:error, :conflict}
end
cond do
!email_address?(email) -> {:error, :bad_request}
!EmailAddresses.available?(email) -> {:error, :conflict}
true -> {:ok, email}
end
This gets rid of unnecessary duplication, and I think is easier to understand.Re: ElixirNitpicks
#16 arg = [1, 2, 3]
# This doesn't crash:
for {key, value} ... end)Re: ElixirNitpicks
#17Interestingly, though I am not a great Rust programmer, nor a great Elixir programmer (I have written programs in both languages). And, gotten a little ways through the amazing Exercism ( https://exercism.org/tracks/elixir ). What I loved about this writeup was the way I could review both by comparing two languages in which I have a moderate understanding. The comparison of imports was very engaging to my brain. I re…
Re: ElixirNitpicks
#18For me it would be the Pin-Operator. Which is only needed cause variables can "mutate". IMHO it's not that common that we need to "reassign" variables, we could life without the looks-like-reassignment. I touched Erlang before, it's hard to get my brain to accept elixir is different in regards of variables :)
Interesting. In our codebase we do this all the time. A quick search revealed 280 occurrences of `some_var = some_var |> ...`. I also find the pin operator much more readable, as the meaning of `{foo, ^bar} = result` doesn't require to know the context. `foo` is being assigned, `bar` is being matched on. No need to know the code before this line to interpret it.
I do remember finding the pin operator confusing when I first started learning Elixir, probably because I'd never seen anything like it in another language. But the confusion didn't last long; it's really not hard to understand. I've never felt like the pin operator was bad for readability.
Re: ElixirNitpicks
#19I add my own nitpick about the with statement. If I start with this code true = is_email_address?(email) true = EmailAddresses.is_available(email) and I decide to turn it into a with like this with true then I have to go line by line replacing = with I understand why with could not work with the = matching operator (it's a macro) but that's about language design, ergonomics and in part not making developers do the jo…
Not sure what you mean - `with` _can_ use the `=` operator, e.g. you could write:
with true = is_email_address?(email),
true = EmailAddresses.is_available(email) do
# something
end
Although this is rather pointless as it's functionally equivalent to just writing: true = is_email_address?(email)
true = EmailAddresses.is_available(email)
# something
`=` is useful inside `with` if you have a clause that _must_ return a particular value or it's an error, i.e. you don't need to match on any other possible return value. But if you don't have at least one clause with `Also, why would the fact that `with` is a macro mean that it can't use `=`?Re: ElixirNitpicks
#20> I do wish migrations were just generated from schemas though, a la Django. This is a weird one to me. I really dislike the magical way Django does this and I'm glad Ecto doesn't. It also allows you to have separate Ecto structs representing different parts of a table in scenarios where that is desirable.
I'm not sure that the Django approach would make sense in Ecto anyway because Ecto schemas are explicitly _not_ "models". The function of a Django/Rails "model" is divided between different concepts like schemas, Ecto.Query, Ecto.Changeset, the Repo etc.