Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What do you think is better about the maybe expression? Just curious, haven't looked into it too deeply and I thought it behaved exactly like when.


Well, I haven't written any Elixir yet, so I'm probably saying that without really knowing.

The main thing, and maybe I just am missing something, but I don't really understand what the point of the 'do' in Elixir's 'with' is? In Erlang you just have the maybe and anything that would go in that do block would just go inside the maybe expression. That seems a lot better to me.

I also just prefer the look of Erlang's maybe. I think maybe is a clearer name for what the statement is doing and the lack of the 'do' block looks better to me and makes it easier to read.


> I think maybe is a clearer name for what the statement is doing and the lack of the 'do' block

It's because basically everything in Elixir is a macro :), and the do block is an argument/parameter to that macro:

   maybe x do
      ...
   end

   # is really 

   maybe x, do: ...

   # which ends up being a macro call with a named parameter

   maybe(x, do: ...)

Same goes for many (all?) other things in Elixir:

   if x do
      ...
   end

   # is really 

   if x, do: ...

   # which ends up being a macro call with a named parameter

   if(x, do: ...)
And so on.

But it took me a very long to come to grips with this, too :)


I think GP is talking more about the fact that you can have a do block, not about what it is.


Yeah exactly, in Erlang the 'do' portion would just go in the same code block as the conditionals.


So you say `maybe` is better than `with` without ever using Elixir, and `with`? I hope your team is not full of people making blanket statements like this.




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

Search: