Hacker News new | ask | show | jobs
by laumars 3280 days ago
Generally yes. But pi is one of those occasions where it only needs to be a constant somewhere and then forgotten about. The last thing you need is developers accidentally mistyping the value of pi causing the output calculations to be wrong.

If altering the precision of pi is something that matters, then the function should take a parameter for the precision rather than the value of pi.

1 comments

Pi is not a variable. I was very careful with my wording to say things like "variable", "expect to change", and "mutable state" so my statement would apply generally. :)
Your wording might have been careful but the author did use pi as a variable in his example and discussed wanting the ability to change it. Since you were essentially agreeing with her/his point, it's forgivable if one then assumes you were also agreeing with his example as well. Hence my counterexample (and hence why I opened with "Generally yes" to signify that I don't disagree with your point but the example provided needs tweaking)
I'm not sure I was agreeing with his point, since I only consider one of his configurations 'valid', and even then only insofar as Pi is a variable (which it isn't). My original statement holds generally and specifically--pass in the things you may want to vary; don't depend on global mutable state.