[erlang-questions] Good form
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,
> hd(lists:nth(maps:get(templateTag, Event),
> agitatedSoundResources(maps:get(scalarTag, Event),
> 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...
Size: 836 bytes
Desc: Digital signature
More information about the erlang-questions