我正在扩展一位前同事的代码(Python3),并亲自发现那些反复self.__local_object.x=some_result
烦人和阻碍可读性的代码。即代替
self.__local_node.sign("computing partition for joining node %f<?<%f"%(
self.__local_node.partition_id,next_neighbour.partition_id))
partition_id = 0
if(next_neighbour != self.__local_node):
partition_id = PartitionID.gen_btw(self.__local_node.partition_id, next_neighbour.partition_id)
我宁愿用
ln=self.__local_node
ln.sign("computing partition for joining node %f<?<%f"%(
ln.partition_id,next_neighbour.partition_id))
partition_id = 0
if(next_neighbour != ln):
partition_id = PartitionID.gen_btw(ln.partition_id, next_neighbour.partition_id)
但是,我还没有熟悉 Python 开发,如果我为引用的对象引入这样的(希望如此)本地别名,我可能会错过一个黄金准则,这将使进一步的维护成为一场噩梦。
PS:不,self.__local_node
' 的值在该代码的任何地方都没有改变。