The elements of programming style

  1. Write clearly - don't be too clever  清晰是最重要的,不要耍聪明
  2. Say waht you mean, simply and directly 词要达意
  3. Use library functions 不要重造轮子
  4. Avoid temprorary variables 避免滥用临时变量
  5. Write clearly - don't sacrifice clarity for "efficiency" 清晰性总是第一位的,比性能重要
  6. Let the machine do the dirty work 又脏又累、繁琐的工作让机器做
  7. Replace repetitive expressions by calls to a common function 代码复用、重构
  8. Parenthesize to avoid ambiguity 使用括号消除歧义
  9. Choos variable names that won't be confused  选择变量名称
  10. Avoid the Fortran arithmetic IF
  11. Avoid unnecessary branches 
  12. Use the good freatures of a language; avoid the bad ones 择善而用
  13. Don't use conditional braches as a substitute for a logical expression
  14. Use the "telephone test" for readability  选用清晰的逻辑表达
  15. Use DO-END and indenting to delimit groups of statements
  16. Use IF-ELSE to emphasize that only one of two actions is to be performed
  17. Used DO and DO-WHILE to emphasize the presence of loops
  18. Make your programs read from top to bottom 保证程序从上至下阅读,慎用GOTO
  19. Use IF...ELSE IF...ELSE IF...ELSE... to implement multi-way branches
  20. Use the fundamental control flow constructs 使用语言提供的本征控制结构
  21. Write first in an easy-to-understand pseudo-language' then translate into whatever language you have to use  易于理解的伪代码
  22. Avoid THEN-IF and null ELSE
  23. Avoid ELSE GOTO and ELSE RETURN
  24. Follow each decision as closely as possible with its associated action 将功能和语义相近的代码尽可能的放在一起
  25. Use data arrays to avoid repetitive control sequences 使用循环简化重复
  26. Choose a data representation that makes the program simple 选择和调整数据结构,以使程序简单
  27. Don't stop with your first draft 第一个草稿不能用
  28. Modularize. Use subroutines 模块化
  29. Make the coupling between modules visible 模块耦合清晰
  30. Each module should do one thing well 一次只做好一件事
  31. Make sure eavery module hides something 信息隐藏
  32. Let the data structure the program  数据决定程序整体结构,以数据为中心
  33. Don't patch bad code - rewrite it 重写烂代码
  34. Write and test a big program in small pieces   
  35. Use recursive procedures for recursively-defined data structures
  36. Test input for validity and plausibility  一定要检查输入
  37. Make sure input cannot violate the limits of the program 检查输入在合理范围内
  38. Terminate input by end-of-file or marker, not by count
  39. Identify bad input; recover if possible 
  40. Treat end of file condtions in a uniform manner
  41. Make input easy to prepare and output self-explanatory
  42. Use uniform input formats
  43. Make input easy to proofread
  44. Use free-form input when possible
  45. Use sefl-indentifying input. Allow defaults. Echo both on output
  46. Localize input and output in subroutines
  47. Make sure all variables are initialized before use 保证所有变量使用前初始化
  48. Don't stop at one bug  BUG多多
  49. Use debugging compilers
  50. Initialize contants with DATA statements or INITIAL attributes; initialize variables with executable code 显式的初始化常量
  51. Watch out for off-by-one errors 小心多一错误
  52. Take care to branch the right way on equality 小心处理变量相等情形
  53. Avoid mutiple exits from loops
  54. Make sure your code "does nothing" gracefully
  55. Test programs at their boundary values  测试代码边界
  56. Program defensively  防御编程
  57. 10.0 times 0.1 is hardly ever 1.0
  58. Don't compare floating point numbers just for equality 避免比较两个浮点数是否相等
  59. Make it right before you make it faster  调优之前要保证代码正确
  60. Keep it right when you make it faster    调优过程中要保证代码正确
  61. Make it clear before you make it faster  调优过程中要保证代码清晰
  62. Don't sacrifice clarity for small gains in "efficiency" 不要为蝇头小利牺牲清晰性
  63. Let your compiler do the simple optimizations
  64. Don't strain to re-use code; reorganize instead  处处重构
  65. Make sure special cases are truly special
  66. Keep it simple to make it faster   优化过程中要保持简单性 
  67. Don't diddle code to make it faster - find a better algorithm  找一个更好的算法
  68. Instrument your program. Measure before making "efficiency" changes 测量是优化的基础
  69. Make sure comments and code agree 注释避免驴唇不对马嘴
  70. Don't just echo the code with comments - make every comment count
  71. Don't comment bad code - rewrite it 不注释烂代码,重写之
  72. Use variable names that mean something  变量名字要选好,望文生义最好
  73. Use statement labels that mean something
  74. Format a program to help the reader understand it 美化代码
  75. Indent to show the logical structure of a program 美化代码
  76. Document your data layouts
  77. Don't over-comment 少说废话
“近年来程序设计领域最好的一本书。”——Larry O’Brien, Software Development Times, July 29, 2015 Using a simple computational task (term frequency) to illustrate different programming styles, Exercises in Programming Style helps readers understand the various ways of writing programs and designing systems. It is designed to be used in conjunction with code provided on an online repository. The book complements and explains the raw code in a way that is accessible to anyone who regularly practices the art of programming. The book can also be used in advanced programming courses in computer science and software engineering programs. The book contains 33 different styles for writing the term frequency task. The styles are grouped into nine categories: historical, basic, function composition, objects and object interactions, reflection and metaprogramming, adversity, data-centric, concurrency, and interactivity. The author verbalizes the constraints in each style and explains the example programs. Each chapter first presents the constraints of the style, next shows an example program, and then gives a detailed explanation of the code. Most chapters also have sections focusing on the use of the style in systems design as well as sections describing the historical context in which the programming style emerged. Cristina Videira Lopes,加州大学欧文分校信息学教授,致力于大规模数据和系统的软件工程研究。她是施乐帕洛阿尔托研究中心的创始成员,还研发并维护着一个搜索引擎,为基于OpenSimulator的虚拟世界提供帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值