简体   繁体   中英

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.

eg:

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

If it returns anything does it remain impure?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM