[erlang-questions] Orelse and andalso as short-hand for case

Dmitry Belyaev be.dmitry@REDACTED
Mon Jul 23 15:32:46 CEST 2018


How does it mess with types? The andalso and orelse operators should only care about the type of the first operand and it always is boolean.

I personally don't like list comprehension as brackets create additional noise and might not be obvious to other developers.

Also dialyzer may complain about unused value in either of ways, so the cleanest is probably case or if. The latter in Elixir doesn't require else branch which reduces noise a little bit.

On 23 July 2018 21:05:37 GMT+10:00, Jesper Louis Andersen <jesper.louis.andersen@REDACTED> wrote:
>On Sun, Jul 22, 2018 at 9:09 PM Jachym Holecek <freza@REDACTED>
>wrote:
>
>> # Viktor Söderqvist 2018-07-22:
>> >
>> >     Msg /= undefined andalso io:format("Message: ~s~n", [Msg]),
>> >
>> > I this good or bad style?
>>
>> It is horrible style. Pain to read, pain to modify, pain to reason
>about.
>>
>> Simple clear question deserves a simple clear answer. :-)
>>
>>
>​I don't like the style either, mostly because it messes with the
>types.
>andalso and orelse expects boolean expressions, but the style used
>breaks
>that format. However, something like
>
>[x || Msg /= undefined]
>
>doesn't.​
>
>
>-- 
>J.

-- 
Kind regards,
Dmitry Belyaev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180723/de079e03/attachment.htm>


More information about the erlang-questions mailing list