gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:12:40 24 4
gpt4 key购买 nike

哪个是更好的做法? (如果这有所作为,我正在 .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 页。

关于.net - IF/ELSE 语句顺序的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1306158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com