【发布时间】:2011-12-20 16:34:35
【问题描述】:
在使用 VBScript 编程期间,我在函数开始执行操作之前在函数中编写了很多错误检查代码。所以,如果某些预先要求不满足,那么我会执行“退出功能”。所以,例如:
public fucnton func
if not condition then
func = -1
exit function
End If
'Other conditions with exit functions
'Then long code goes here
..........
..........
..........
func = res
End Function
所以,我可以从多个点退出函数。这是好方法吗?在这种情况下,我将得到 if 语句的长 else 分支
也许写得更好:
public fucnton func
if not condition then
func = -1
Else
'Then long code goes here
..........
..........
..........
End If
End Function
请分享你的想法。
【问题讨论】:
标签: coding-style code-readability