[erlang-questions] Use of logical "not" in `case`

Loïc Hoguin essen@REDACTED
Fri Feb 9 10:40:49 CET 2018


On 02/09/2018 10:31 AM, zxq9@REDACTED wrote:
[...]
> foo(Status, Thingy, Assignments) ->
>      case not maps:is_key(Thingy, Assignment) of
>          true ->
>              Assignment = fomulate_assignment(Thingy),
>              NewAssignments = maps:put(Thingy, Assignment, Assignments),
>              {assigned, NewAssignments};
>          false ->
>              {Status, Assignments}
>      end.
[...]
> This isn't a big deal either way of course (I find them both equally readable), but I am curious if anyone has a strong opinion on the issue and why. Which would you prefer to encounter when reading a project to understand how it works on github?

Oh boy. I would definitely get tripped by this. Or at the very least 
have some eyebrow action.

I have no problem with it in something like C because there's usually no 
'else' clause in these cases and it's therefore very easy to read the 
intent.

But in Erlang's case what you effectively do is invert the boolean value 
below and that requires a little more gymnastic. And I don't think it 
matches what one would say in a conversation because why would you 
mention the case where nothing happens at all?

-- 
Loïc Hoguin
https://ninenines.eu



More information about the erlang-questions mailing list