SC programming

R19: programming with ADTs

Recipes: Test-first programming approach -> writing an ADT -> writing a program with ADTs

区别在于test-first和ADT都是从规范出发,然后测试,然后具体实现,可能会改变实现的方式根据不同的规范。而在编程时需要我们根据实际情况选用数据类型,选用我们需要实现的大概步骤以得到想要的数据。然后才进行和测试先行编程方法一样的步骤。

  1. Choose datatypes. Decide which ones will be mutable and which immutable.
  2. Choose static methods. Write your top-level main method and break it down into smaller steps.
  3. Spec. Spec out the ADTs and methods. Keep the ADT operations simple and few at first. Only add complex operations as you need them.
  4. Test. Write test cases for each unit (ADT or method).
  5. Implement simply first. Choose simple, brute-force representations. The point here is to put pressure on the specs and the tests, and try to pull your whole program together as soon as possible. Make the whole program work correctly first. Skip the advanced features for now. Skip performance optimization. Skip corner cases. Keep a to-do list of what you have to revisit.
  6. Iterate. Now that it’s all working, make it work better. Reimplement, optimize, redesign if necessary.

case study: matrix multiplication

Ideas including static typing, testing, spec, immutability, and interfaces.