Naming future objects and their methods

Cameron Simpson cs at zip.com.au
Sun Apr 15 18:00:29 EDT 2012


On 15Apr2012 00:22, Stefan Schwarzer <sschwarzer at sschwarzer.net> wrote:
| 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.
[...]
|     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'd call it "packet", and was_sent just "sent".

  if packet.sent(timeout=1.0):

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

If you 'aint falling off, you ar'nt going hard enough.  - Fred Gassit



More information about the Python-list mailing list