Tips from A philosophy of software design

Design Principles

Make investments in design

  1. Complexity is incremental: you have to sweat the small stuff.
  2. Working code isn’t enough.
  3. Make continual small investments to improve system design.
  4. Design it twice.
  5. The increments of software development should be abstractions, not features.

Simple Interface, Deep Implementation

  1. Modules should be deep.
  2. Interfaces should be designed to make the most common usage as simple as possible.
  3. It’s more important for a module to have a simple interface than a simple implementation.
  4. General-purpose modules are deeper.
  5. Seperate general-purpose and special-purpose code.
  6. Different layers should have different abstractions: no pass-through methods, aware of interface duplication.
  7. Pull complexity downward: pull the complexity down to implementation, keep the interface simple.
  8. Define errors and special cases out of existence: don’t throw unnecessary error to users, try to handle it in your code.

Comment for reader, not for writer.

  1. Comments should describe things that are not obvious from the code.
  2. Software should be designed for ease of reading, not ease of writing.

Summary of Red Flags: the presence of any of these symptoms in a system suggests that there is a problem with the system’s design

  • Shallow Module: the interface for a class or method isn’t much simpler than its implementation.
  • Information Leakage: a design decision is reflected in multiple modules.
  • Temporal Decomposition: the code structure is based on the order in which operations are executed, not on information hiding.
  • Overexposure: An API forces callers to be aware of rarely used features in order to use commonly used features.
  • Pass-Through Method: a method does almost nothing except pass its arguments to another mehod with a similar signature.
  • Repetition: a nontrivial piece of code is repeated over and over.
  • Special-General Mixture: special-purpose code is not cleanly separated from general-purpose code.
  • Conjoined Methods: two methods have so many dependencies that its hard to understand the implementation of one without understanding the implementation of the other.
  • Comment Repeats Code: all of the information in a comment is immediately obvious from the code next to the comment.
  • Implementation Documentation Contaminates Interface: an interface comment describes implementation details not needed by users of the thing being documented.
  • Vague name: the name of a variable or method is so imprecise that it doesn’t convery much useful information.
  • Hard to Pick Name: it is difficult to come up with a precise an intuitive name for an entity.
  • Hard to Describe: in order to be complete, the documentation for a variable or method must be long.
  • Nonobvious Code: the behavior or meaning of a piece of code cannot be understood easily.

Resources

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值