python 3 constant

Ben Finney ben+python at benfinney.id.au
Thu Jun 23 09:04:37 EDT 2011


"Waldek M." <wm at localhost.localdomain> writes:

> Dnia Thu, 23 Jun 2011 17:22:37 +1000, Ben Finney napisał(a):

> > The ability to re-bind any attribute, even ones which the author
> > thought should be constant, makes writing unit tests much easier. I
> > don't see that putative benefits of constant bindings would be
> > anywhere near as valuable.
>
> Primo, isn't it usually the author that does the unit testing?

I don't see how that's relevant. I'm referring to run-time re-binding of
attributes, without the need for changing the code.

> Anyway, correct me if I'm wrong but I always thought that unit tests
> should prove the correctness and quality of the code under test,

Right. Which often involves special set up of the environment in which
that code runs, in order to conduct a proper test.

If the test I need to perform involves demonstrating what the code under
test will do with different values for a name you consider constant,
then I have Python's ability to re-bind that name at run-time.

> Secundo, one can say that re-binding gives the freedom to change what
> one likes; I'd say that I'd also like the freedom to decide what is
> mutable and what is not.

And I, as the user of your code, say that you don't get to dictate how I
use it. I will take the authors's recommendations under advisement, but
I reject any authority to restrict what I can do with it.

Unit tests are just an obvious example. The real lesson here is that the
reciient of the code you write can, and probably will, use it in ways
you never expected. It's not for you to decide which of those uses are
permitted.

> Of course, it is just my personal opinion. It might be not pythonic,

Right. One useful phrase to remember from the founder of the Python
language is that “We're all consenting adults here”.

Indicate through the API and its documentation how you recommend I use
your code; but treat me as an adult capable of making my own decisions
about what risks I accept. Understand that I will be using the code you
wrote in the way I see fit.

-- 
 \     “Don't be afraid of missing opportunities. Behind every failure |
  `\         is an opportunity somebody wishes they had missed.” —Jane |
_o__)                                          Wagner, via Lily Tomlin |
Ben Finney



More information about the Python-list mailing list