2d
awarded Good Answer
Mar
2
comment In Erlang how is using registered processes different from global variables in a traditional language?
The advantage of HonestToGoodnessPid or ServiceFactory is that your API does not lie about what it relies on. With register, a thing that you rely on is obfuscated, making it difficult to test. In order to test, you must know what registered processes must exist. Ideally, a function's behavior depends only on its arguments. Of course, some functions also receive; in those cases, it should be determined by a second thing: messages that it listens for and receives. register provides a third hidden (and therefore unwelcome) side channel by behavior can be affected.
Mar
2
comment In Erlang how is using registered processes different from global variables in a traditional language?
re locating long-running services: Pretty sure the same thing can be done without resorting register. One problem with register is that everybody and their mama now knows about processes in the registry. Another is that does_not_exist ! foo can blow up in your face. HonestToGoodnessPid ! foo cannot, even if that process is defunct, non-responsive, or whatever. If you're going to get around that by doing whereis(does_not_exist), then you might as well pass in ServiceFactory, and call it instead of whereis.
Mar
2
revised In Erlang how is using registered processes different from global variables in a traditional language?
"such" appears to be errant and extraneous; added 3 characters in body
Mar
2
comment In Erlang how is using registered processes different from global variables in a traditional language?
I had the exact same question. This does not seem at all unreasonable. I'm also new to Erlang, but it very much seems to me that register would have the same problems as global variables.
Mar
2
revised Can you use a list (or other collection) to specify what messages to receive in Erlang?
edited title
Mar
2
comment Can you use a list (or other collection) to specify what messages to receive in Erlang?
Just because you cannot imagine how this could be useful does not mean that it's crazy. The messages are not unexpected; the set of expected messages is specified dynamically in a list, rather than statically in code.
Mar
1
reviewed Approve suggested edit on What is the difference between node.js and io.js?
Mar
1
comment Can you use a list (or other collection) to specify what messages to receive in Erlang?
I don't think you understand the question: the list is not static. Imagine you are given an ARBITRARY list of the form given in the question (that's why there's an Etc() there), and the same code must be able to handle such a list. Your second suggestion ignores the requirement that non-matching messages do not get removed from the mailbox, or that any removed message needs to be put back in the same position.
Mar
1
comment Is there a way to tell whether a function has a matching clause without calling it in Erlang?
nit: callee can fool you by returning a value of the same form though. Seems better to use try + catch, as suggested in other answer. But still, thank you!
Feb
28
comment Is there a way to tell whether a function has a matching clause without calling it in Erlang?
I guess this solution DOES call callee to probe whether it has matching clause. Still, it does distinguish between match failure and other failures, which in many cases is just as good.
Feb
28
comment Is there a way to tell whether a function has a matching clause without calling it in Erlang?
Ah, I thought get_stacktrace might be the key. For some reason, it wasn't doing what I thought it would when I first tried it. Thanks!
Feb
28
asked Can you use a list (or other collection) to specify what messages to receive in Erlang?
Feb
27
asked Is there a way to tell whether a function has a matching clause without calling it in Erlang?
Feb
21
comment Linux - Threads and Process
Thank you. This explanation is excellent. This information makes me want to kill myself.
Feb
19
comment DTrace on Ubuntu, how-to?
SO needs a feature where I can award more points to answers that go above and beyond. Thank you.
Feb
19
comment Is there a way for a process to find out that it's been orphanned in Erlang?
I think that only works if Parent is not long-lived.
Feb
19
comment Is there a way for a process to find out that it's been orphanned in Erlang?
I've read a decent chunk of LYSE. So far, I've only seen supervisors used to restart processes. Shutdown only seems to be done when the supervisor itself is shut down.
Feb
18
revised Is there a way for a process to find out that it's been orphanned in Erlang?
added 93 characters in body
Feb
18
comment Is there a way for a process to find out that it's been orphanned in Erlang?
The stuff you mention in the first paragraph would not tell you that a process is not reachable anymore. Some of those things ensure that it will always be reachable (e.g. register).
1 2 3 4 5