Naming future objects and their methods

Stefan Schwarzer sschwarzer at sschwarzer.net
Sat Apr 14 18:22:33 EDT 2012


Hello,

I wrote a `Connection` class that can be found at [1]. A
`Connection` object has a method `put_bytes(data)` which
returns a "future" [2]. The data will be sent asynchronously
by a thread attached to the connection object.

The future object returned by `put_bytes` has a `was_sent`
method which will return `True` once the sender thread has
actually sent the data via a socket call. An example might
look like

    put_result = connection.put_bytes(data)
    if put_result.was_sent(timeout=1.0):
        print "Data has been sent."
    else:
        print "Data hasn't been sent within one second."

However, I'm not comfortable with the combination of the
names of the future and its method. After all, not the
`put_result` was sent, but the data that was the argument in
the `put_bytes` call. Maybe `data_was_sent` is better than
`was_sent`, but `put_result.data_was_sent()` doesn't feel
right either.

What do you think would be a "natural" way to name the
future returned by `put_bytes` and possibly the `was_sent`
method attached to it? Can you even come up with nice naming
rules for futures and their methods? :-)

I tried to find suggestions by using a search engine and
StackOverflow, but wasn't successful. PEP 3148 [3] describes
an API, but it's quite abstract (`Executor.submit`,
`Future.result` etc.).

[1] https://bitbucket.org/sschwarzer/connection/src/f705e612f764/connection.py
[2] http://en.wikipedia.org/wiki/Future_%28programming%29
[3] http://www.python.org/dev/peps/pep-3148/

Stefan



More information about the Python-list mailing list