<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Yes, same here. Anything clever but unreadable I would put in an
informatively-named function. I might call this
print_unless_undefined/1.<br>
<br>
Ivan<br>
<br>
<br>
<div class="moz-cite-prefix">On 23/07/2018 15:16, Dmitry Kolesnikov
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:DD272F69-1909-43A5-A230-F9FA7F9CA866@gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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="" moz-do-not-send="true">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=""
moz-do-not-send="true">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=""
moz-do-not-send="true">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=""
moz-do-not-send="true">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 class="" clear="all">
</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=""
moz-do-not-send="true">erlang-questions@erlang.org</a><br
class="">
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a><br
class="">
</div>
</blockquote>
</div>
<br class="">
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
============================================================
Ivan A. Uemlianin PhD
Llaisdy
Ymchwil a Datblygu Technoleg Lleferydd
Speech Technology Research and Development
<a class="moz-txt-link-abbreviated" href="mailto:ivan@llaisdy.com">ivan@llaisdy.com</a>
@llaisdy
llaisdy.wordpress.com
github.com/llaisdy
<a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/ivanuemlianin">www.linkedin.com/in/ivanuemlianin</a>
festina lente
============================================================ </pre>
</body>
</html>