[erlang-questions] Orelse and andalso as short-hand for case
Viktor Söderqvist
viktor@REDACTED
Thu Jul 26 14:05:56 CEST 2018
Thank you all for the diverse opinions!
Especially, I liked this point from Dmitry Kolesnikov:
> Long time ago, I’ve used andalso syntax but it never stays longer at
> code repository due to readability. It has been refactored to
> function(s) with guards or pattern match.
I think it is the process from prototyping to maintained code.
Refactoring involves gradually adding names to things by introducing
functions, adding specs and rewriting hacks into proper solutions. A
spec with a return type like false | ok | {error, Reason} would make me
reconsider the andalso trick. I guess this process gradually makes the
code change style from dynamically typed style (LISP, Perl) to
statically typed style (ML, Haskell). I find this interesting.
Viktor
On 2018-07-22 14:25, Viktor Söderqvist 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
>
More information about the erlang-questions
mailing list