That variable name is awful, but I'm not quite able to come up with something more concise.
Long names aren't necessarily a problem as long as they explain well what is this variable. You could call it enable_x
to stress the fact its a boolean that will enable a particular treatment. But using booleans to force an execution path should be avoided whenever possible.
What is the general practice ?
To avoid this kind of flag entirely. The most elegant design is to refactor using classes and overrides :
class A:
def foo(x):
start_of_foo(x)
bar(x)
remaining_of_foo(x)
def bar(x):
pass
class B(A):
def bar(x):
do_something_with(x)
Then you can use B()
or A()
based on situation
Alternatively, if you are reluctant to use a class for this :
def foo(x, mybar=bar):
start_of_foo(x)
mybar(x)
remaining_of_foo(x)
def bar(x):
pass
def specific_bar(x):
do_something_with(x)
.save()
, and I'd like to be able to not have it happen if for whatever reason I'm in the shell putting out fires, and don't want the updating to happen. – Adam Barnes Mar 27 '19 at 11:21save
doesn't sound like something you want to do especially to disable something. Could you ask a question about your original problem, possibly on SO, so we could help the best way possible ? – Diane M Mar 27 '19 at 12:22.save()
, and have added the flag in question to the arguments to bypass the updating should one need to. – Adam Barnes Mar 27 '19 at 13:09