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

Mikael Pettersson mikpelinux@REDACTED
Fri Feb 9 11:17:12 CET 2018


I do prefer the "true" case first, since that more closely emulates a
traditional "if" statement.  However, the condition should then be
written to match.  In your case, I'd prefer a helper function
is_key_absent/2 (or sth like that) rather than a barely visible "not".

Just my 0.02 SEK.

On Fri, Feb 9, 2018 at 10:40 AM, Loïc Hoguin <essen@REDACTED> wrote:
> 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
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list