Control-Unusual Structures

Multiple Returns from a Routine
1. Use a return when it enhances readability.
2. Use guard clauses(early returns or exits) to simplify complex error processing.
3. Minimize the number of returns in each routine.

Recursion
1. Make sure the recursion stops.
2. Use safety counters to prevent infinite recursion.
3. Limit recursion to one routine.
4. Keep an eye on the stack.
5. Don't use recursion for factorials or fibonacci numbers.

Some possible rewrite strategies for goto
1. Rewrite with nested if statements.
2. Rewrite with a status variable.
3. Rewrite with try-finally.

Guidelines for using gotos
1. Use gotos to emulate structred control constructs in languages that don't support them directly.
2. Don't use the goto when an equivalent built-in construct is avaiable.
3. measure the performance of any goto used to improve efficiency.
4. Limit yourself to one goto label per routine unless you're emulating structured constructs.
5. Limit yourselft to gotos that go forward, not backward, unless you're emulating structured constructs.
6. Make sure all goto labels are used.
7. Make sure a goto doesn't create unreachable code.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值