The seven steps of a programer
Overview of the Seven Steps
The seven steps proposed by Hilton et al. (2019) present an intriguing strategy for initiating a new project involving programming. This approach is concisely summarized in Figure 1. In this discussion, we will elaborate on these steps, drawing upon the work of Hilton et al. (2019).
All steps are then described in the sections below.
Step 1 - Project definition using simple examples
This step involves dedicating time to conceptualize the project and breaking it down into manageable tasks. Begin by manually sketching a diagram of the project, highlighting key topics, strategies for addressing challenges, and estimating the number of primary algorithms required for completion. This should also encompass the subdivision of the project into smaller tasks, their interconnections, and any sequential order for their execution, as depicted in Figure 2. An effective approach in this stage is crucial as it simplifies the subsequent steps.
Example 1
Imagine we need to develop a C++
algorithm to calculate the total fat content ($y$) of a portion of ice cream. Assume this response variable is determined by the amounts of butyric fat ($x_1$) and vegetable fat ($x_2$). Let $E[y]$ represent the expected value of $y$, defined as:
We can manually compute the total fat $y$ for specific values of $x_1$ and $x_2$. For instance, if $x_1=2$ and $x_2=1$, then:
$$y=10-0.5\times2+0.6\times 2^2-0.6\times 1+0.2 \times 1^2+0.1\times 2 \times 1 = 11.2.$$Now, let’s assume the secondary goal is to optimize the fat content in the ice cream formulation based on this model. This involves searching for the global minimum on the response surface. Consequently, we can break down our project into two tasks:
If you encounter difficulties in these tasks, it’s often due to a gap in specific domain knowledge, such as a lack of expertise in mathematics:
Therefore, during this step, it is essential to identify all the necessary domain knowledge and address these gaps before proceeding to the next stage. Sometimes, this knowledge may stem from specialized areas such as computer science, sports, agriculture, statistics, or engineering.
Step 2 - Write everything you did
In this phase, it is crucial to meticulously record every action undertaken to resolve the project’s challenges or tasks. Ensure that your notes are clear and detailed enough for others to replicate your solutions effortlessly. Be cautious not to overlook steps that might seem obvious, such as basic operations like multiplying $x$ by $y$, or the sequence in which tasks are to be executed.
Example 2
Consider the task of calculating $f(x, y) = x^y + 3x$ for $x=2$ and $y=4$. Here’s how you could document the process in a detailed and comprehensible manner:
By following these explicit steps, anyone with basic mathematical skills should be able to reach the same result.
Step 3 - Generalize
The goal now is to transform the specific steps from earlier into a universal algorithm that applies to a broader range of cases, not just specific parameter values. Here are two common methods to achieve this generalization:
For instance, let’s generalize our Example 2 by adapting the steps from Step 2, replacing the specific occurrences of 2 with a variable $x$:
It is important to note that the initial multiplication should start with $x \times x = x^2$. Therefore, we multiply $x$ by itself $y-1$ times to obtain $x^y$. This leads us to the following generalized steps for any values of $x$ and $y$:
Algorithm sketch 1
start with x = 2 and y = 4
n[1] = x
Count up from i in 1 to y-1
n[i+1] = n[i] * x
z = n[y] + 3 * x
z is the answer
Step 4 - Test Your Algorithm
Testing your algorithm is a crucial step to ensure the correctness of steps 1-3 before advancing to step 5. Here are some key actions and considerations during this stage:
At times, the generalization in step 3 might be incomplete, leading to a revisit of steps 1-2. This oversight often occurs when not all potential cases are considered or when mathematical proofs are lacking.
A notable example of an algorithmic error is seen in Example 2. What if $y=0$ or $y<0$? Our algorithm incorrectly addresses these cases. For example, with $x=2$ and $y=0$, the algorithm erroneously calculates $2^0=2$ instead of the correct $2^0=1$. Also, for any $y \leq 0$, the algorithm erroneously tries to count from $1$ to $y-1 < 0$, which is not applicable for natural numbers, leading to an error. Therefore, we must ensure $|y| \in \mathcal{N}_{0}$, where $\mathcal{N}_{0}$ represents the set of natural numbers including zero. Consequently, we should aim to generalize our algorithm to accommodate a broader range of cases:
Algorithm Sketch 2
y must be an integer number.
Start with x = 2 and y = 4.
If y=0 {
n[1] = 1;
i=0;
} else {
Count from i = 1 to |y|-1;
If y < 0 {
n[1] = 1/x;
n[i+1] = n[i] * (1/x);
} else {
n[1] = x;
n[i+1] = n[i] * x;
}
}
z = n[i+1] + 3 * x;
z is the answer.
When encountering problems with our algorithm at this stage, we have two options:
Example 3
The data in Figure 4 originates from an algorithm that accepts a single parameter, $N$, belonging to the set $\mathcal{N}_{0}$, where $\mathcal{N}_{0} = \mathcal{N} \cup \{ 0 \}$ denotes the set of natural numbers including zero. This algorithm generates a sequence of output values corresponding to each specified value of $N$.
References
[1] Hilton, AD; Lipp, GM; Rodger, SH, Translation from Problem to Code in Seven Steps, Comped 2019 Proceedings of the Acm Conference on Global Computing Education (2019), pp. 78-84.
Answers
Example 3
Algorithm Sketch 3
Set N as a non-negative integer (Natural number with zero).
Initialize N with a specific value n.
Define the sequence parameters:
Minimum Value = 4 * N
Maximum Value = 9 * N + 6
Sequence Increment = 3
Set x[1] to the Minimum Value.
Iteratively calculate the sequence:
For each iteration i,
if x[i-1] < Maximum Value,
then x[i] = x[i-1] + Sequence Increment.
else,
break the loop.
The sequence x represents the final answer.
# N = 6
N=5
seq <- seq(4*N, 9*N+6, 3)
cat("The answer is", seq)
## The answer is 20 23 26 29 32 35 38 41 44 47 50
Citation
- For attribution, please cite this work as:
- BibTeX citation
@misc{oliveira2020seven,
author = {Oliveira, Thiago},
title = {The seven steps of a programer},
url = {https://prof-thiagooliveira.netlify.app/post/the-seven-steps-of-a-programer/},
year = {2020}
}
Did you find this page helpful? Consider sharing it 🙌