Book Review of “The practice of programming” (Ⅳ)

The practice of programming



Chapter 4 Interfaces

A good programmer should always be good at designing. The essence of design is to balance competing goals and constraints. When we do programming, we need to design a friendly, portable and flexible interface.

Among the issues to be worked out in a design are:

  interfaces,  information hiding,  resource management,  error handling

These factors are not separated, but combined.

So, how to do a good designer? On the other word, how to handle the issues above perfectly?

The first step is to construct a general frame, leaving out the details. Then we need to test it by thinking of every possible situation, and improve it. By the way, it is essential for our frame to work in changeable environments. In this circumstance, we need specifications to constraint our work. Generally speaking, specifications had better be worked out in advance.

To prosper an interface must be well suited for its task-simple, general, regular,predictable, robust-and it must adapt gracefully as its users and its implementation change.

  • Hide implementation details
  • Avoid global variables
  • Don‘t reach behind the user‘s back
  • Do the same thing the same way everywhere

About Resource Management:

  • Initializationma
  • Maintaining state
  • Sharing and copying
  • Cleaning up (Free a resource in the same layer that allocated it)

To avoid problems, it is necessary to write code that is reentrant,  which means that it works regardless of the number of simultaneous executions.

The text of error messages, prompts, and dialog boxes should state the form of valid input.

Charpter 5 Debugging

  • Good Clues
  1. Look for familiar patterns
  2. Examine the most recent change
  3. Don‘t make the same mistake twice
  4. Debug it now, not later
  5. Get a stack trace
  6. Read before typing
  7. Explain your code to someone else
  • No Clues
  1. Make the bug reproducible
  2. Divide and conquer
  3. Study the numerology of failures
  4. Display output to localize your search
  5. Write self-checking code
  6. Write a logfile
  7. Draw a picture
  8. Use tools
  9. Keep records
  • Last Resorts

    This may be  the time to use a good debugger to step through the program.

  • Non-reproducible Bugs
  1. Check whether all variables have been initialized
  2. If the bug changes behavior or even disappears when debugging code is added, it may be a memory allocation error

Chapter 6 Testing

  • Test as You Write the Code
  1. Test code at its boundaries
  2. Test pre- and post-conditions
  3. Use assertions
  4. Program defensively
  5. Check error returns
  • Systematic Testing
  1. Test incrementally
  2. Test simple parts first
  3. Know what output to expect
  4. Verify conservation properties
  5. Compare independent implementations
  6. Measure test coverage
  • Test Automation
  1. Automate regression testing
  2. Create self-contained tests
  • Test Scaffolds
  • Stress Tests
  • Tips for Testing
  1. Programs should check array bounds (if the language doesn‘t do it for them), but the checking code might not be tested if the array sizes are large compared to typical input.
  2. Make the hash function return a constant, so every elemen1 gets installed in the same hash bucket.
  3. Write a version of your storage allocator that intentionally fails early, to test your code for recovering from out-of-memory errors.
  4. Before you ship your code. disable testing limitations that will affect performance.
  5. Initialize arrays and variables with some distinctive value, rather than the usual default of zero; then if you access out of bounds or pick up an uninitialized variable, you are more likely to notice it.
  6. Vary your test cases
  7. Provide ways to make the amount and type of output controllable when a program is run; extra output can help during testing.
  8. Test on multiple machines, compilers, and operating systems.
时间: 2024-08-03 07:18:18

Book Review of “The practice of programming” (Ⅳ)的相关文章

Code Review Engine Learning

相关学习资料 https://www.owasp.org/index.php/Code_review https://www.owasp.org/images/8/8e/OWASP_Code_Review_Guide-V1_1.doc http://cwe.mitre.org/about/index.html 目录 1. INTRODUCTION: 代码审计介绍 2. PREPARATION: 代码审计需要的准备 3. SECURITY CODE REVIEW IN THE SDLC: 系统生命

FRP represents an intersection of two programming paradigms.

Functional programming Functional programming is a programming paradigm where you model everything as a result of a function that avoids changing state and mutating data. Reactive programming Reactive programming is the practice of programming with a

【转载】发个有用的:国际学术期刊会议大排名

Rank Conference Full Name1 OSDI Operating Systems Design and Implementation2 SOSP Symposium on Operating Systems Principles3 SIGCOMM Special Interest Group on Data Communication4 MOBICOM Mobile Computing and Networking5 SIGGRAPH Annual Conference on

提高专业能力的书单

Code Complete (2nd edition) by Steve McConnell The Pragmatic Programmer Structure and Interpretation of Computer Programs The C Programming Language by Kernighan and Ritchie Introduction to Algorithms by Cormen, Leiserson, Rivest & Stein Design Patte

转载--我与英语技术书籍

原文:http://www.cnblogs.com/KnightsWarrior/p/EnglishTechBooks.html 我与英语技术书籍 2013-09-05 00:01 by 圣殿骑士, 17877 阅读, 122 评论, 收藏, 编辑 前言(Introduction) 前些天写了一篇<程序猿也爱学英语(上),有图有真相>,大概介绍了我学英语的一些基本资料以及心得体会,本来接下来该发中篇,但<程序猿也爱学英语(中),有图有真相>实在太长,为了方便读者阅读以及多方面考虑,

(收藏) 程序员必看的书

无意在网上看到的一个书单,挺不错的,都是些经过时间考验的好书,保存一下. 黑客与画家 深入理解计算机系统 代码大全 2 人月神话 淘宝技术这十年 白帽子讲Web安全 重构 代码整洁之道 Web前端黑客技术揭秘 浪潮之巅 免费 罗辑思维 简约至上——交互式设计四策略 Head First 设计模式 程序员的数学思维修炼 互联网时代的软件革命——SaaS架构设计 设计模式之禅 程序员修炼之道 结网 程序员面试逻辑题解析 (Puzzles for Programmers and Pros) 像程序员一

程序员必读书籍及导读指南

最近在网上看了一个非常好的帖子<程序员一生必读的书>(我的腾讯微博上有分享该贴子链接,有兴趣就点击进去看看吧),该贴的第一个张图片是一个雷达图, 这张图是由ThoughtWorks(全球软件设计与定制领域的领袖级企业)的资深人士提供的,它将程序员要读的书分为四个类别,每个类别又分为初级.进阶和高级读物,并用黄色三角形点出了强烈推荐阅读的书籍.四个类别包括: 编程实践(Coding Practice) 设计与架构(Design & Architecture) 方法学(Methodolog

读《世界是数字的》后有感

<世界是数字的>是一部科普读物,出自顶尖计算机科学家Brian W.Kernighan之手,如果你不知道此人是谁的话,那么你或许知道      The Practice   of Programming中文名程序设计实践, BrianW.Kernighan与R.Pick合著,如果你也不知道程序设计实践,那么你肯定知道The C Programming Language,没错这本K&R,就是Kernighan与C语言之父里奇的著作,此书被誉为C语言的圣经,影响着一代又一代的程序员. 这本

《世界是数字的》阅读笔记

<世界是数字的>是由世界顶尖计算机科学家Brian W.Kernighan写的,Brian W.Kernighan曾为贝尔实验室计算机科学研究中心高级研究人员,现为普林斯顿大学教授.他是AWK语言和AMPL语言的发明人,还参与过UNIX和许多其他系统的开发,同时出版了The C Programming Language.The Practice of Programming.The Elements of Programming Style等在计算机领域影响深远的著作. Kernighan主张