On Thu, Sep 4, 2014 at 1:22 PM, Rustom Mody <rustompm...@gmail.com> wrote: > | Effect-free programming > | -- Function calls have no side effects, facilitating compositional reasoning > | -- Variables are immutable, preventing unexpected changes to program data > by other code > | -- Data can be freely aliased or copied without introducing unintended > effects from mutation > > So to answer your question: print statements are side-effecting and therefore > obstruct > compositional reasoning.
Yeah, fine. One small problem: Computers aren't built to do nothing. "Effect-free programming" is utterly valueless and purposeless. To make a program actually useful, you need to have some effect somewhere. So where do you do that? Where do you permit a function with side effects? If you force *everything* to be in the return value, you lose any possibility of partial results - for instance, if it takes two weeks to render a ray-traced animation, you actually spend the entire two weeks building up a single, gigantic return value, which some outside system (which is presumably allowed to have side effects) then saves somewhere. In the meantime, you have absolutely no idea how far it's progressed - no information that it's completed frame 6 and is working on frame 7, nothing. Because telling the user anything is a side effect. And if my function f calls show_status_to_user() which has side effects, then f has side effects too, and you can no longer reason purely about f. The impurity that makes for practicality (hey, isn't there something in the Zen of Python about that?) pollutes upwards until all you'll have will be pockets of pure functional code that execute quickly enough to not need any intermediate output. That doesn't equate to "abolish print", that just means that you separate the guts from the UI - which is good advice for any system, no matter what its structure. ChrisA -- https://mail.python.org/mailman/listinfo/python-list