re: Class vs Function based programming simplified VIEW POST

FULL DISCUSSION
 

Sorry to nitpick, but your example for an impure function is not impure iff (if and only if) PI is a constant (which is very likely in this case, why would someone chaange the value of pi?). So if PI is defined as const PI = ... the function is 100% pure.

You dont have to pass everything as an argument to a pure function, but calling the function with the same arguments has to always return the same value (and have no observable sode effects).

 

If we use the value from Math.PI then this is indeed pure but I said in the example that PI is a global variable and defined outside the function.
A function is reusable and the value of PI will depend on the context. One may choose to define PI = 3.14159 instead of 3.14 and the result will vary.
Bdw my point was simply to say that don't use a global variable that might change. Thank you for your suggestion.

code of conduct - report abuse