首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

古龙的编码作风

2012-10-29 
古龙的编码风格如果古龙是一个程序员的话他的编码风格或许会是这样的package liveness//他已经记不得是什

古龙的编码风格
如果古龙是一个程序员的话
他的编码风格或许会是这样的

package liveness;//他已经记不得是什么时候写的这段代码public class Transfer{private static final Object tieLock = new Object();       //每个程序员都会有感到不安时候public void transferMoney(  Account from,  Account to,  int amount  ){synchronized(from){synchronized(to){if((from.getBalance()-amount)<0){from.debit(amount);to.credit(amount);}}}}//这里他感到了些许的安全public void transferMoneySafe(  final Account from,  final Account to,  final int amount  ){class Helper{public void transfer(){if((from.getBalance()-amount)<0){from.debit(amount);to.credit(amount);}}}int fromHash = System.identityHashCode(from);int toHash = System.identityHashCode(to);if(fromHash < toHash){synchronized(from){synchronized(to){new Helper().transfer();}}}else if(fromHash < toHash){synchronized(to){synchronized(from){new Helper().transfer();}}}else{synchronized(tieLock){synchronized(to){synchronized(from){new Helper().transfer();}}}}}}


大量的换行,加上大量的旁白(代码注释)
或许他的代码风格很不错 1 楼 jichongchong 2008-12-17   噢买疙瘩!

热点排行