Defensive Programming

本文探讨了程序员在编码时采用防御编程策略的重要性,将其比作驾驶员在复杂交通环境中考虑最坏情况。通过预设边界条件,确保代码在面对异常输入或错误时仍能正常工作,提倡以预防错误而非事后修复的态度进行编程。
Once the programmer starts coding
	he should use defensive programming.
	
This is similar to defensive driving
	which means driving under worst-case scenarios
		other drivers violating traffic laws, unexpected events or obstacles, etc
	
Similarly, defensive programming means developing code 	
	such that it works correctly
		under the worst-case scenarios from its environment. 

For instance, when writing a function
	one should assume worst-case inputs to that function, 	
	i.e., inputs that are too large, too small
	or inputs that violate some property, condition, or invariant
	the code should deal with these cases
		even if the programmer doesn't expect them to happen under normal circumstances.

note:
	the goal is not to become an expert at fixing bugs		
	but rather to get better at writing robust (mostly) error-free programs in the first place. 

	As a matter of attitude
		programmers should not feel proud when they fix bugs
		but rather embarrassed that their code had bugs. 	
		If there is a bug in the program, it is only because the programmer made mistakes.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

穿越辩证法

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值