Control-Unusual Structures

原创 2004年10月12日 23:31:00

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.

基于Problem Solving with Algorithms and Data Structures using Python的学习记录(5)——Searching

5.1.目标 能够解释和实现顺序查找和二分查找。 能够解释和实现选择排序,冒泡排序,归并排序,快速排序,插入排序和 shell 排序。 理解哈希作为搜索技术的思想。 引入映射抽象数据类型。 使用哈希实...
  • HeatDeath
  • HeatDeath
  • 2017年03月30日 13:39
  • 727

下载电子书Problem Solving with Algorithms and Data Structures using Python

哥哥的拥有欲望很强烈,看到书就想下载,手里痒痒就拿网络爬虫来练手。 1、下面是源代码,刚下载两页就老提示断网: Exit with code 1 due to network error: Hos...
  • kaihuangzheng0050
  • kaihuangzheng0050
  • 2017年04月13日 17:33
  • 983

Java 9 Data Structures and Algorithms.pdf

Java 9 Data Structures and Algorithms.pdf https://www.packtpub.com/application-development/java-9-...
  • Cloud_Strife_1985
  • Cloud_Strife_1985
  • 2017年07月16日 09:48
  • 552

129.View the Exhibits and examine the structures of the PROMOTIONS and SALES tables.

129.View the Exhibits and examine the structures of the PROMOTIONS and SALES tables.
  • dwj19830118
  • dwj19830118
  • 2016年03月08日 10:49
  • 547

120.View the Exhibits and examine the structures of the PRODUCTS, SALES, and CUSTOMERS

120.View the Exhibits and examine the structures of the PRODUCTS, SALES, and CUSTOMERS
  • dwj19830118
  • dwj19830118
  • 2016年03月07日 17:01
  • 540

Problem Solving with algorithms and data structures using Python 翻译计划

作为学习python中读得最完整的一本书,而市面上确实没有中文版,用python讲数据结构和算法的书,所以打算逐步翻过来。 主要目的是实现一次精读。用一段英文一段中文的方式。插图只好复制过来...
  • ppabcde
  • ppabcde
  • 2014年03月14日 10:36
  • 3822

XML document structures must start and end within the same entity

在做mybatis 自动生成代码的时候,对xml读取时报XML document structures must start and end within the same entity错误,发现这个...
  • StivenGang
  • StivenGang
  • 2014年08月14日 00:56
  • 1368

123.View the Exhibits and examine the structures of the PRODUCTS, SALES, and CUSTOMERS

123.View the Exhibits and examine the structures of the PRODUCTS, SALES, and CUSTOMERS
  • dwj19830118
  • dwj19830118
  • 2016年03月07日 17:25
  • 975

UVA 540 team queue

Team Queue  Queues and Priority Queues are data structures which are known to most comput...
  • u013480370
  • u013480370
  • 2014年07月16日 16:18
  • 509

Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)

Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)
  • u012860063
  • u012860063
  • 2014年07月18日 21:56
  • 979
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Control-Unusual Structures
举报原因:
原因补充:

(最多只允许输入30个字)