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
- Command
- Function
- Pipeline (Dataflow) / Script / Algorithm
- System / App
2. Design Techniques - How to come up with a design?
- Working at least 3 examples by hand
- Writing the subproblems as normal english as comments
- Drawing the subproblems on a paper
3. Design Strategies
- Decomposition
- Top-down vs. Bottom-up (Divide and Conquer)
- Forward vs. Backward
- Breadth first vs. Depth first
- Problem Recognition and Searching for Analogous Problems & Solutions
- Simplification & Generalisation
- Abstraction
- Recursion
- Dynamic Programming
- Backtracking
- Encapsulation
- Modularization
- State Machine
4. Design Principles
- DRY - Don’t repeat yourself
- KISS - Keep it simple, stupid
- Generality
- Plan for Changes
5. Design Aspects
- Points of View
- Flow - Transformations
- Data - Representations
- Mapping - Represent and Interpret
- World/Problem/Solution Domain - Information
- Meaning
- Use
- Data Structure 1 - Using and Composing the Data Building Blocks from the Programming Language
- Possible Values
- Relationships / Structure
- Behavior / Operations
- World/Problem/Solution Domain - Information
- 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
)
- Sequence (
- Factors to consider in designing data structures
- Ease of implementation - flow
- Time complexity
- Space complexity
- Mapping - Represent and Interpret
- State
- Side Effect
- Pure Function
- Modifier
- Side Effect
6. Design by Contract (Advanced) - assert
- Precondition - What does contract expect?
- Postcondition - PostWhat does contract guarantee?
- Invariant - What does contract maintain?
7. Fundamental Building Blocks
- Input
- Output
- Math and Logic
- Conditional Execution
- Repetition
8. Design Alternatives - Pros & Cons
9. Design Products
- Stages
- Algorithm
- Solution Design
- Development Plan
- Format
- Pseudocode (e.g., comments)
- 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
All rights reserved.