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

Robert Raschke rtrlists@REDACTED
Sun Jul 22 15:23:57 CEST 2018


I think this kind of style originated in languages like Perl, Lua and
Javascript for writing shorthand code for default values. Things like "v =
v or -1".

>From there things spread, leading to odd combinations, like the examples
you quote with side effects.

In the end it is about readability, sometimes the shortcut can read nicer
than a case or if statement. And sometimes it is clearer to be a teensy bit
more verbose.

Robby


On 22 Jul 2018 14:25, "Viktor Söderqvist" <viktor@REDACTED> wrote:

> Hey everyone,
>
> I've seen these short-circuit operators with a non-boolean second
> operand, usually where the second operand is doing some side-effect and
> the return value is not important. It seems to be a trend. Example:
>
>     Msg /= undefined andalso io:format("Message: ~s~n", [Msg]),
>
> I this good or bad style?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180722/50509d44/attachment.htm>


More information about the erlang-questions mailing list