New answers tagged python
3
votes
What side-effects, if any, are okay when importing a python module?
One big issue with your example logging code is that both those lines of code could fail for a multitude of reasons (read-only filesystem, invalid path, lack of filesystem permissions, etc). These ...
-3
votes
What side-effects, if any, are okay when importing a python module?
TL;DR
Side effects are unacceptable until they are unavoidable.
Convention
Python libraries are "quick and dirty" - they rely heavily on global shared state and there is little to be done ...
13
votes
What side-effects, if any, are okay when importing a python module?
However, in a lot of cases, the side-effects are hard to avoid or may be desirable.
They are never hard to avoid, and they are never desirable. Or maybe they somewhat are hard to avoid, because it ...
21
votes
What side-effects, if any, are okay when importing a python module?
logging
# Creates a logfile
logging.basicConfig(filename="module.log")
No, don't do it!
Now git status is dirty, it shows an untracked file.
Protect this with a __main__ guard,
or let ...
6
votes
Accepted
When the stack frames become computationally expensive
There are two questions here:
What is the cost of function call?
Is inlining a function worth it?
So first of all a function call costs. Saving registers, setting up frame, two jumps, loading ...
-1
votes
When the stack frames become computationally expensive
function call overhead
When you speak of stack frames that are "computationally expensive"
you're really talking about the expense incurred to save state,
transmit arguments, receive result, ...
Top 50 recent answers are included
Related Tags
python × 2020design × 157
object-oriented × 154
design-patterns × 131
python-3.x × 96
django × 83
java × 76
coding-style × 76
architecture × 67
unit-testing × 66
algorithms × 64
object-oriented-design × 60
programming-languages × 58
javascript × 56
c++ × 55
programming-practices × 53
testing × 41
web-applications × 41
web-development × 39
php × 37
exceptions × 37
functions × 35
c × 34
database × 33
class × 33