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

Danil Zagoskin z@REDACTED
Mon Jul 23 17:32:23 CEST 2018


Hi!

I find this style convenient for debugging.
Sometimes you need some binding to be logged, but only under some rare
conditions. After the problem is fixed the added code should be removed or
commented-out.

Adding a simple if (or case) costs you 4 lines and an extra tabulation.
Removing/disabling that requires selecting several lines, then
deleting/commenting them.

Adding a wrapper function invades the code in two places.
Removing that requires extra seeking to the helper function. Disabling
(commenting the call) requires disabling the function too,
to avoid unused function warning. Much pain.

A single-liner with andalso/orelse is easy to write (shorter than other
options) and easy to remove/disable (just jump to line + single dd or I in
vim).

On Sun, Jul 22, 2018 at 3:25 PM 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
>


-- 
Danil Zagoskin | z@REDACTED
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180723/0d88da6b/attachment.htm>


More information about the erlang-questions mailing list