加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

.net – IF / ELSE语句顺序的最佳实践

发布时间:2020-12-17 00:09:22 所属栏目:大数据 来源:网络整理
导读:哪个更好的做法? (我在.Net中编码,如果这有所作为) IF condition = true THEN ...true action--even if rare...ELSE ...actionEND IF 要么 IF condition = [most common condition] THEN ...most common action....ELSE ...least common actionEND IF 根据C
哪个更好的做法? (我在.Net中编码,如果这有所作为)
IF condition = true THEN
   ...true action--even if rare...
ELSE
   ...action
END IF

要么

IF condition = [most common condition] THEN
   ...most common action....
ELSE
   ...least common action
END IF
根据Code Complete的作者Steve McConnell,你应该

“Put the case you normally expect to
process first. This is in line with
the general principle of putting code
that results from a decision as close
as possible to the decision…[putting
the normal case after the if
] puts the
focus on reading the main flow rather
than on wading through the exceptional
cases,so the code is easier to read
overall.”

Code Complete,第2版,第356-357页.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读