Naming future objects and their methods

Laurent Pointal laurent.pointal at free.fr
Sun Apr 15 15:08:36 EDT 2012


Stefan Schwarzer wrote:

> 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.
<zip>

Just an idea:
put_result ==> dataput
was_sent ==> sent

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


-- 
Laurent POINTAL - laurent.pointal at laposte.net
3 allée des Orangers - 91940 Les Ulis - France
Tél. 01 69 29 06 59




More information about the Python-list mailing list