News for hackers. Stuff that matters.
Re:Say “no” to import side‐effects in Python by ta0967 on Saturday April 05, 2014 @09:35AM (#7537026)

    from __future__ import print_function
Re:Say “no” to import side‐effects in Python by makomk on Saturday April 05, 2014 @09:49AM (#7537058)
As I understand it, "from __future__ import ..." statements are actually a special type of statement that doesn't actually import a module at all - they just use similar syntax for compatibility reasons. There is an actual __future__ module, also for compatibility reasons, but importing it has no side-effects.
Re:Say “no” to import side‐effects in Python by chrismorgan on Saturday April 05, 2014 @09:54AM (#7537075)
Future statements do import something as well, when run, but their primary purpose is changing the behaviour of the compiler for the current file. They have no behaviour outside of that file, so that is not a publicly visible side-effect.
Re:Say “no” to import side‐effects in Python by ta0967 on Saturday April 05, 2014 @03:47PM (#7538194)
Whether they import a module or not is - IMO - irrelevant. I was responding to this claim: In Python, side-effects are simply not acceptable at all. One should instead put the code with the side-effect in a function and call it. `__future__` imports are obviously and purposefully side-effectful, there's no `print_function()`.
Re:Say “no” to import side‐effects in Python by einhverfr on Saturday April 05, 2014 @09:45AM (#7537054)
That's a side effect, right? Your module after the import is not the same as it was before, or am I missing something?
Re:Say “no” to import side‐effects in Python by ak217 on Saturday April 05, 2014 @12:55PM (#7537590)
Future imports are not imports at all (the fact that they use the same syntax as imports is misleading IMO). They are tags that instruct the interpreter to turn on certain features only when interpreting the given file. They must appear before any statements in the file, and they take effect before interpretation of the file starts. You could argue that this constitutes an import side effect, but that's neither here nor there, and not helpful.
Re:Say “no” to import side‐effects in Python by chrismorgan on Saturday April 05, 2014 @09:56AM (#7537080)
It only changes the behaviour for the current file, so it's not a side-effect.
Re:Say “no” to import side‐effects in Python by einhverfr on Saturday April 05, 2014 @12:20PM (#7537482)
That seems too narrow a view of side effect.

Which of the following are side effects?

1. Initializing a point of sale printer, checking for errors, and raising exceptions if, say, it is out of paper? Let's say this is a cash drawer driver and the cash drawer connects through the printer, and if the printer is out of paper, the drawer won't open properly (this happens btw). I would call this a side effect as well as a separation of concerns violation btw. However it is not likely to be a visible change to other modules.

2. Check for the presence of a binary and if found, cache the path to it, perhaps instantiating another object to do so? Definitely a side effect there, but not publicly visible.

3. Initializing an external library's environment (as happened in this case)? Done wrong it crashes the system but I suspect the segfault was not intended. Again it isnt clear to me you have a publically visible side effect intended.