Yoda Notation
flyfish 2016-2-22
《星球大战》里有个 Yoda 大师
他说话是这样子的:
Yoda: Bring him here. Question him we will.
Yoda: Around the survivors a perimeter create.
Yoda: If Dooku escapes, rally more systems to his cause we will.
Yoda: Concentrate all your fire on the nearest starship.
Yoda: Mmm. Lost a planet, Master Obi-Wan has. How embarrassing. How
embarrassing.Yoda: Truly wonderful, the mind of a child is.
说的都是倒装句
假设
int i=0;
if(i==1){}
防止手误写成了 if(i=1)
所以写成了 if(1==i) 这就是Yoda Notation(Yoda 表示法)
更好的方式是如果出现if(i=1),编译器应提示警告。 比如 warning C4706: 条件表达式内的赋值.
因为if(i==1) 读起来,更容易理解