Managing Complexity

Make it work

Make it known

Make it right

Make it fast

You shouldn't even be programming if you're not doing test driven development.

Not only unit tests.

Until you know what you're building, it just doesn't make sense to invest a ton of money or resources into building something that your users may not even want.

So I believe at the onset, start with user testing, and then move into automated testing.

  • Code should be fine grained meaning code should do one thing. 解耦
  • Code should be self documenting. 代码每一个部件都要有意义
  • Favor pure, immutable functions. 缩减 state 管理所占用的空间

Abstractions should:

  • reduce complexity 减少复杂度
  • reduce coupling 减少相互影响
  • increase cohesion 增加凝聚力 逻辑是否是一个 Group
  • increase portability 轻便,减少影响增加凝聚

Refactor through promotion:重构

Composition over inheritance

Do not confuse convention for repetition:做一个确切的事情要用同一个方法去实现

Well-structured code will naturally have a larger surface area

Team rules for managing complexity

  • Be mindful over the limitations of your entire team and optimize around that.

  • Favor best practices over introducing idioms however clever they may be.

  • Consistency is better than righteousness.

  • Follow the style guide until it doesn't make sense for your situation.

Tactical rules for managing complexity

  • Eliminate hidden state in functions. 函数中有因为参数值的改变会发生不同的作用,这在测试时候很难处理。
  • Do not break the Single Responsibility Principle.
  • Extracting to a method is one of the most effective refactoring strategies available.
  • If you need to clarify your code with comments then it is probably too complex.如果有需要的要提取到参数去描述。