[erlang-questions] Concept of Side-effect
Rapsey
rapsey@REDACTED
Thu Sep 17 08:28:32 CEST 2009
It means the same thing in Erlang as it does anywhere else. A function has a
side effect, if it changes some state. Doing something with files, sockets,
databases, processes etc. are side effects.
A side effect free function is dependent only on its input values. When it
has finished, it produces an output from those input values and nothing else
(list_to_binary/1 for instance).
You should strive to have as many side effect free functions as possible.
They are easy to test, easy to understand and easy to work with.
Functions that change state is where your bugs will generally be. The more
you change state, the more complex your program becomes. If you change state
all over the place, you are creating something very difficult to understand
and debug.
Sergej
On Thu, Sep 17, 2009 at 12:26 AM, Kaiduan Xie <kaiduanx@REDACTED> wrote:
> Hi,
>
> Can someone explain what does side-effect means in Erlang? What is
> side-effect free function, and why we need to write side-effect free
> function? A concrete example is preferred.
>
> Thanks,
>
> kaiduan
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>
More information about the erlang-questions
mailing list