minggeJS icon indicating copy to clipboard operation
minggeJS copied to clipboard

凑个热闹,好的程序读起来像诗一样,只是正巧能让计算机运行它

Open lexrus opened this issue 9 years ago • 4 comments
trafficstars

为了代码的可读性,请尽量不要嵌套使用三元运算符。

如 minggeJS 中有这么一段代码可读性极差的代码:

obj = i == 0 ? findTrue ? findTrue.find ? system.find.call(obj, match[0]) : system.filter.call(obj, match[0]) : new D().init(match[0], document) : system.filter.call(obj, match[i]);

如果一定要嵌套,最好是把逻辑块用圆括号包起来提高可读性,如:

var result = (1 ? 2 : 3) ? 4 : 5;

lexrus avatar Dec 16 '15 08:12 lexrus

明哥不需要可读性,明哥对可读性了如指掌

luckyadam avatar Dec 16 '15 09:12 luckyadam

@lexrus 惊现唐兄

paincompiler avatar Dec 16 '15 11:12 paincompiler

了如指掌啊,人形自走编译器不需要可读性。

jamesliu96 avatar Dec 16 '15 13:12 jamesliu96

明哥对 JS 底层了如指掌,并不需要可读性

banrikun avatar Dec 16 '15 15:12 banrikun