Design Code

这个章节的目的是教会你如何设计代码逻辑,如何思考,如何实现。

面向对象

Methods

Structs and Traits

impl for struct、struct / function can be generic

Generic Types 泛型 & Trait & Lifetime

Trait

impl Trait for Struct, default impl

Trait Object

Assoacited Trait

Think in expression | Iterators | Option | Rich Types

Zero Cost Abstraction(CPU 概念的举例,只存在我们脑海,本质是 01) - OPtion and Result 随处可见、零成本抽象、迭代

Polymorphism

  • No Classical Inheritance

  • Traits

  • Generics

  • Design Code

    • Build Structure, Convert Business Knowledge to Type System/Enum
      • No Classes
      • ALGEBRAIC TYPE SYSTEM
      • data normalization
      • state machines
  • Write Code / Read Code / Test Code

    • Work with compiler.
  • Maintenance Code / Support their Code

    • Trust code, 少维护