[Twisted-Python] Private positional argument API anti-pattern

Glyph glyph at twistedmatrix.com
Fri Jun 21 17:48:05 MDT 2013

On Jun 21, 2013, at 8:05 AM, exarkun at twistedmatrix.com wrote:

> Hello,
> I've noticed there are a couple public APIs in Twisted now that accept a "private" positional argument.  I use scare quotes because I don't see how it's actually possible to make a positional argument private.
> Given a function defined like this:
>   def foo(_bar=None):
>       ...
> There is no indication that a use like this is problematic:
>   foo(3)
> Perhaps the situation will be different with keyword-only arguments, but for positional arguments I think it's unproductive and perhaps even confusing to name arguments this way.
> I suggest we fix the couple places where this has been done so far and we avoid introducing any new instances.
> FWIW, I found two examples of this in Twisted using:
>   $ grep -E '\W_reactor' twisted/ -r --include '*.py' | grep -E 'def\W'

I second this suggestion.

Furthermore, in most cases where one is tempted to make a reactor *attribute* private, it's probably best to make it public.  There are lots of legitimate uses to parameterize the reactor and to discover which one a particular object is using.

The case where one is tempted to make an argument private like this seems to be somewhere that we feel that something should be parameterized "only for testing".  If we need to parameterize it for testing, our users probably need to parameterize it for *their* tests, too.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20130621/ec943a70/attachment.html>

More information about the Twisted-Python mailing list