3 ms·
That's fair. I think it makes more sense to write a function you know is functional and then test for expected output. I'm not sure under what circumstances you
by acbabis 11y ago
That's fair. I think it makes more sense to write a function you know is functional and then test for expected output. I'm not sure under what circumstances you wouldn't be sure if your code was functional.
- catnaroek 11y agoI can think of situations where a compiler couldn't figure out on its own that your code is purely functional. For example, when you do dynamic programming, you internally use mutation (memoizing previous results) to speed up the evaluation of a recursive pure function. Outside parties shouldn't be able to see anything impure going on. Lazy evaluation is a special case of this idea. But I can't think of any situation where the programmer shouldn't know beforehand whether the procedure he or she's implementing evaluates a pure function.