基本防御性编程
Possible Duplicate:
Favorite (Clever) Defensive Programming Best Practices
I am always advised by some programmers to pay concentration to easy debugging. What is defensive programming and to which extend should it be considered while practicing?
And one more important question: is there any key things to consider while coding and what are they?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看看
编程
Have a look at
Programming
根据经验,如果您发现自己在想“这将永远是正确的”,请在该位置写入
ASSERT(condition)
。这可能是防御性编程的核心;)。As a rule of thumb -- if you catch yourself thinking "this will always be true", write
ASSERT( condition)
in that place. That is probably the core of what defensive programming should be ;).如果防御性编程只意味着一件事,那就应该广泛使用断言。
这里是一篇关于何时和在哪里使用
断言
。If defensive programming meant only one thing , that should be use assert extensively.
Here is a good article about when and where to use
assert
.http://en.wikipedia.org/wiki/Defective_programming
防御性编程意味着您检查文件是否存在并且您是否有权打开它,而不是仅仅尝试打开它并捕获任何最终的异常。
(仅举个例子)
http://en.wikipedia.org/wiki/Defensive_programming
Defensive programming means, that you check if a file exists and if you have the permissions to open it instead of just trying to open it and catching any eventual exceptions.
(Just an example)