Reading Assignment: All of Programming Chapter 1 Introduction

Source: All of Programming

The key aspect of programming is **metacognition**–think about how you think. According to Wikipedia, metacognition is “cognition about cognition”, “thinking about thinking”, “knowing about knowing”, becoming “aware of one’s awareness” and higher-order thinking skills.

The key skill of programming are universal–learning a new language is largely just a matter of learning its syntax.

Planing ahead is more important than dive into coding. Programming should be done in a manner that comes up with a complete plan(or algorithm) first and build(implement in code) second.

Given the problem of prime numbers, the author stressed the importance that **programming is used to solving a class of problem**.

## How to Write a Program

## Algorithms

Definition: An algorithm is a clear set of steps to solve any problem in a particular class.

## Step 1: Work an Example Yourself

Work at least one instance of the problem, involving drawing a diagram of the problem by hand.

2 Problems:

- the problem is ill specified
- lack domain knowledge

## Step 2: Write Down What You Just Did

Write down the steps to solve the *particular instance*, or write down a set of instructions.

An instruction with kind of complex is fine, as long as it has a clear meaning.

Difficulty: Thinking about the *exact* steps.

## Step 3: Generalize Your Steps

### Method 1

2 steps to generalize:

- taking particular values
- replacing the instance with the variables.

### Method 2

find repetition

## Step 4: Test Your Algorithm

To ensure our steps right by testing with different values other than previous used ones. The only way to be completely sure that your algorithm is correct is to formally prove its correctness.

Common mistakes:

- misgeneralizing
- cases that did not consider

## Some Examples

…

## Next Steps

…