[erlang-questions] Noob question: Need some help to limit process spawing
Garrett Smith
g@REDACTED
Sun Aug 16 18:06:31 CEST 2015
On Sun, Aug 16, 2015 at 8:37 AM, Edward Halls <ehalls@REDACTED> wrote:
> Perhaps some better syntax highlighting can help you spot this in the
> future.
>
> A good ide will also tell you when there are unused variables.
Better programming conventions - in particular making the code say
what's going on - is even better than a super intelligent IDE that
tells you what's wrong as you're typing. I turn those helper features
off. Or, I would if Emacs had them on by default.
> On 16 Aug 2015 2:22 pm, "Robert Raschke" <rtrlists@REDACTED> wrote:
>>
>> Could be the typo? Value2 vs Val2.
>>
>> On Aug 16, 2015 12:44 PM, "avinash D'silva" <evnix.com@REDACTED> wrote:
>>>
>>> Hi,
>>>
>>> I have these lines code:
>>>
>>> timer:apply_after(5*1000,mymodule,myfunction,[Value]),
>>> timer:apply_after(5*1000,mymodule,myfunction,[Value]),
>>> timer:apply_after(5*1000,mymodule,myfunction,[Value]),
>>> timer:apply_after(5*1000,mymodule,myfunction,[Value]),
>>> timer:apply_after(5*1000,mymodule,myfunction,[Value]),
>>>
>>> "myfunction" looks like this:
>>> myfunction(Value)->
This should be a function:
>>> Val2=iolist_to_binary([Value,"_P"]),
You're making a decision to add this suffix here? Why? A well named
function will make that obvious.
Any time you find yourself adding 2, 3, 4s to the end of a variable,
stop. What's the actual name of the variable there? I mean, what is
it? Use that.
Oh, and "value" should be "term" here. Kidding of course - it's no
doubt a value, but take advantage of the variable name. Just spend a
moment and think about what that thing actually is in the context of
your function/problem.
I'd flatten this all out:
>>> case pg2:get_members(Value2) of
>>>
>>> [] ->
>>> {ok,P}=mymodule:start_link(),
>>> pg2:join(Value2,P2),
>>> gen_server:call(P2,{push,Msg});
>>> Otherwise ->
>>> [Px|_]=Otherwise,
>>> gen_server:call(Px,{push,Msg})
>>> end,
to be something like:
handle_members(members_for_xxx(XXX))
I don't know what XXX is here (that's a bad name too) but it should make sense.
>>> the problem is instead of creating a single process of mymodule.
>>> there are 5 processes, as time taken to register the process is more,
I didn't answer your question as I fixate on code clarity and it's an
emotional blocker for me :)
More information about the erlang-questions
mailing list