擅长:python、mysql、java
<p>因为<code>local_node</code>和<code>next_neighbour</code>是对称的,所以最好将代码提取到一个单独的方法中:</p>
<pre><code>def compute_partition(self, a, b):
a.sign("computing partition for joining node %f<?<%f" % (
a.partition_id, b.partition_id))
partition_id = 0
if a != b:
partition_id = PartitionID.gen_btw(a.partition_id, b.partition_id)
etc...
....
self.compute_partition(self.local_node, next_neighbour)
</code></pre>
<p>在我看来更具可读性。而且,使用双下划线必须有很好的理由(或借口)。检查是否有可能在你的情况下摆脱他们。你知道吗</p>