[erlang-questions] Good form

Hugo Mills hugo@REDACTED
Thu Mar 14 23:35:50 CET 2019

On Thu, Mar 14, 2019 at 06:12:35PM -0400, Donald Steven wrote:
> Sometimes, when a variable is bound then used only once in a
> function call, it seems easier just to just use what it is bound to
> directly in the function call, bypassing the first step.
> Here's an example:
> getSound(Event) ->element(evaluate:probableElement(evaluate:probabilities(maps:get(elementTag,
> Event))),
> hd(lists:nth(maps:get(templateTag, Event),
> agitatedSoundResources(maps:get(scalarTag, Event),
> maps:get(registerTag,
> Event), maps:get(transpositionTag, Event))))).
> Alternatively, I could have declared, for example, a raft of
> variable like ElementNumber, ElementTag, TemplateTag, etc.
> I realize that this all-in-one-compact version tends towards
> inscrutabel c code liek &X++ ?.
> How do you approach the temptation to avoid discrete steps in favor
> of compactness?

   I don't find it tempting at all. :)

   The discrete steps can be useful documentation, because you can
give the interim variables meaningful names, explaining (a little)
what it is that you're doing.

   It also helps to break up the calls for formatting and readability,
particularly if you have functions with multiple parameters in the


Hugo Mills             | The most exciting phrase to hear in science, the one
hugo@REDACTED carfax.org.uk | that heralds new discoveries, is not "Eureka!", but
http://carfax.org.uk/  | "That's funny..."
PGP: E2AB1DE4          |                                          Isaac Asimov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190314/ce14f863/attachment.bin>

More information about the erlang-questions mailing list