Page 87 -
P. 87
sharing your code
Life’s full of choices
When it comes to deciding what to do here, there’s
no shortage of suggestions.
That’s soooo easy. Simply create
another function called “print_lol2”,
right? You could then import the
function you want using the specific
form of the import statement. It’s not
that hard, really...
Yeah, that might just work.
You could edit your module’s code and define a new function called
print_lol2, then code up the function to perform the nested printing
When you want to use the original function, use this specific form of the
import statement: from nester import print_lol. When you want
to use the new, improved version of the function, use this import statement:
from nester import print_lol2.
Which would work, but…
But that suggestion is twice
the work...which might be OK
sometimes...but the creation of a
second, almost identical, function
seems wasteful to me.
Right. A second function is wasteful.
Not only are you introducing an almost identical function to your
module, which might create a potential maintenance nightmare, but
you’re also making things much more difficult for the users of your
module, who must decide ahead of time which version of the function
they need. Adding a second function makes your module’s application
programming interface (API) more complex than it needs to be.
There has to be a better strategy, doesn’t there?
you are here 4 51