[erlang-questions] Good form
Robert Carbone
erlang@REDACTED
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*.
http://blog.erlang.org/core-erlang-optimizations/
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.
/scriptculture.com /
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,
>> 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
> sequence.
>
> Hugo.
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190315/47f69d5a/attachment.htm>
More information about the erlang-questions
mailing list