[erlang-questions] Random newbie stuff
Ulf Wiger
ulf@REDACTED
Sun Nov 4 16:51:14 CET 2007
2007/11/4, Dennis Byrne <dbyrne@REDACTED>:
>
>
> Hello Ulf,
>
> If you have a function that is 100% predictable, couldn't there be some
> serious performance gains given that the function is frequently passed the
> same message? In other words, why put a core to work calculating the result
> you gave last time someone sent you a given message? It would be better to
> use this function to spawn a process that could use the process dictionary
> as a cache (one that would never expire).
>
> Unless ... are gets and puts to the dictionary thread safe?
>
Hmm, these are two different questions.
The immutability part means that stuff like this is not possible in Erlang:
void foo( int &i )
{
i++;
}
int main()
{
int bar = 5; // bar == 5
foo( bar ); // bar == 6
foo( bar ); // bar == 7
return 0;
}
(from http://developer.kde.org/~wheeler/cpp-pitfalls.html, one of many web
pages listing C++ pitfalls).
The fact that a function will return the same value every time it is called
with the same input, doesn't mean to imply that you have to call it every
time you have a certain set of values. (-:
It's not a matter of efficiency. It's rather a sanity thing. When you debug
functional code, it takes only moments to determine that a function depends
only on its input parameters. Once you've done that, you can figure out what
it does, and rest assured that this will always hold.
BR,
Ulf W
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071104/e75c8b55/attachment.htm>
More information about the erlang-questions
mailing list