Shubham
Shubham

Reputation: 330

Does an impure function return anything?

An impure function does not return anything. That is what my computer textbook says. I am not sure it is correct as by definition an impure function is a function which changes the state of the parameters passed to it. The parameter is generally an object.

e.g.:

void impurefunc(Class object)
{
   object.var = 9; //object's variable changed
}

If it returns anything does it remain impure?

Upvotes: 1

Views: 785

Answers (1)

Ry-
Ry-

Reputation: 225044

An impure function does not return anything. That is what a computer textbook says.

It’s wrong. An impure function can indeed return anything after doing whatever impure things it does. This is true in Java and every other language I know of.

Upvotes: 2

Related Questions