2. Design a Solution

"First, solve the problem. Then, write the code." – John Johnson

"Without requirements or design, programming is the art of adding bugs to an empty text file." - Louis Srygley

"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare in his Turing Award Lecture (1980)

"Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming." - Rob Pike

"Write stupid code that uses smart objects."

Breaking down (decomposing) the problem into (hierarchical) sub-problems (i.e. sub-goals) until each one of them is solvable with coding + Integration (combining).

1. The Nature of the Problem

  1. Command
  2. Function
  3. Pipeline (Dataflow) / Script / Algorithm
  4. System / App

2. Design Techniques - How to come up with a design?

  1. Working at least 3 examples by hand
  2. Writing the sub­problems as normal english as comments
  3. Drawing the sub­problems on a paper

3. Design Strategies

  1. Decomposition
    1. Top-down vs. Bottom-up (Divide and Conquer)
    2. Forward vs. Backward
    3. Breadth first vs. Depth first
  2. Problem Recognition and Searching for Analogous Problems & Solutions
  3. Simplification & Generalisation
  4. Abstraction
  5. Recursion
  6. Dynamic Programming
  7. Backtracking
  8. Encapsulation
  9. Modularization
  10. State Machine

4. Design Principles

  1. DRY - Don’t repeat yourself
  2. KISS - Keep it simple, stupid
  3. Generality
  4. Plan for Changes

5. Design Aspects

  1. Points of View
    1. Flow - Transformations
    2. Data - Representations
      • Mapping - Represent and Interpret
        1. World/Problem/Solution Domain - Information
          1. Meaning
          2. Use
        2. Data Structure 1 - Using and Composing the Data Building Blocks from the Programming Language
          1. Possible Values
          2. Relationships / Structure
          3. Behavior / Operations
      • Classes of Data Structures
        • Primitive vs. Composite (Containers)
        • Mutable vs. Immutable
        • Built-in vs. Programmer-defined
        • Flat vs. Nested (& Recursive)
      • Types of Containers in Python
        • Sequence (list, tuple , str)
        • Set (set, frozenset)
        • Multiset (collection.Counter)
        • Mapping (dict)
      • Factors to consider in designing data structures
        • Ease of implementation - flow
        • Time complexity
        • Space complexity
  2. State
    • Side Effect
      1. Pure Function
      2. Modifier

6. Design by Contract (Advanced) - assert

  1. Precondition - What does contract expect?
  2. Postcondition - PostWhat does contract guarantee?
  3. Invariant - What does contract maintain?

7. Fundamental Building Blocks

  1. Input
  2. Output
  3. Math and Logic
  4. Conditional Execution
  5. Repetition

8. Design Alternatives - Pros & Cons

9. Design Products

  1. Stages
    1. Algorithm
    2. Solution Design
    3. Development Plan
  2. Format
    1. Pseudocode (e.g., comments)
    2. Visualisation

Checkout Question:

Do I have a development plan (which coding tasks should I do and in which order)?

1 Abuse of terminology - Relates to all the concepts of Data Type, Data Structure and Abstract Data Type



Copyright © 2019 Shlomi Hod.
All rights reserved.

results matching ""

    No results matching ""