<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">This is a clear case for Option data type…</div><div class=""><br class=""></div><div class="">I would prefer to use explicit definition of a function that is able to handle undefined values </div><div class=""><br class=""></div><div class="">```</div><div class="">print(undefined) -></div><div class=""> undefined;</div><div class="">print(Msg) -></div><div class=""> io:format("Message: ~s~n", [Msg]).</div><div class="">``` </div><div class=""><br class=""></div><div class="">Alternatively, there is a parse transforms for composition of maybe/option types (<a href="https://github.com/fogfish/datum/blob/master/doc/category.md#option" class="">https://github.com/fogfish/datum/blob/master/doc/category.md#option</a>)</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">Best Regards, </div><div class="">Dmitry </div><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 23 Jul 2018, at 16.32, Dmitry Belyaev <<a href="mailto:be.dmitry@gmail.com" class="">be.dmitry@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">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.<br class="">
<br class="">
I personally don't like list comprehension as brackets create additional noise and might not be obvious to other developers.<br class="">
<br class="">
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.<br class=""><br class=""><div class="gmail_quote">On 23 July 2018 21:05:37 GMT+10:00, Jesper Louis Andersen <<a href="mailto:jesper.louis.andersen@gmail.com" class="">jesper.louis.andersen@gmail.com</a>> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div dir="ltr" class=""><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">On Sun, Jul 22, 2018 at 9:09 PM Jachym Holecek <<a href="mailto:freza@circlewave.net" class="">freza@circlewave.net</a>> wrote:<br class=""></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># Viktor Söderqvist 2018-07-22:<br class="">> <br class="">
> Msg /= undefined andalso io:format("Message: ~s~n", [Msg]),<br class="">
> <br class="">
> I this good or bad style?<br class="">
<br class="">
It is horrible style. Pain to read, pain to modify, pain to reason about.<br class="">
<br class="">
Simple clear question deserves a simple clear answer. :-)<br class="">
<br class=""></blockquote></div><div class="gmail_quote"><br class=""></div><div class="gmail_quote"><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">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</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br class=""></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">[x || Msg /= undefined]</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br class=""></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">doesn't.</div><br clear="all" class=""></div></div></blockquote></div><br class="">
-- <br class="">
Kind regards,<br class="">
Dmitry Belyaev</div>_______________________________________________<br class="">erlang-questions mailing list<br class=""><a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class="">http://erlang.org/mailman/listinfo/erlang-questions<br class=""></div></blockquote></div><br class=""></body></html>