[erlang-questions] Good form
Fri Mar 15 16:16:18 CET 2019
I couldn't agree more with Hugo & Richard -
We are programming in a high level language here; you shouldn't be
trying to compact your code unless you are /trying /to obfuscate it.
And as far as I understand it,*the compiler is going to make those
substitution optimizations for you*.
So absolutely, line up your variables nicely, give them good names,
keep things in short & make it readable.
Other peeps, & more probably your future-self, will thank you.
All this is great Erlang coding technique and solid habits to be forming.
- Rob C.
On 3/14/19 6:35 PM, Hugo Mills wrote:
> 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
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions