Skip to content

Commit d7bc76c

Browse files
author
Frank Versnel
committed
Renamed 'Week1', 'Week2' to 'Debugging1', 'Debugging2'.
Folders are renamed because they don't correspond with Weeks necessarily. Also added some more bugs.
1 parent 3ee2403 commit d7bc76c

File tree

13 files changed

+95
-25
lines changed

13 files changed

+95
-25
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ summarize:
187187
3. An observable failure.
188188
3. You learned how to use `console.log` to look for infections to lead you to
189189
the defect.
190+
4. But most of all: don't panic! :)
190191

191192
<sup>1</sup> Zeller, Andreas - Why Programs Fail, Second Edition: A Guide to
192193
Systematic Debugging (2009)

Debugging1/MAKEME.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Homework debugging 1
2+
3+
Fix all the bugs in `Debugging1/homework`.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
We want to know if our train arrives soon or not.
33
If our train arrives within two hours we consider it to be soon.
4+
Normally hours wrap around from 24->0. For this assignment we're gonna
5+
assume hours don't wrap, so hour 24 + 1 becomes 25 and so on.
46
57
Hint: try changing the variables `currentHour` and `trainArrivesHour`
68
to find the defect.
@@ -10,5 +12,5 @@ let currentHour = 8;
1012
let trainArrivesHour = 9;
1113

1214
if((trainArrivesHour - currentHour) < 3) {
13-
console.log("your train arrives soon");
15+
console.log("our train arrives soon");
1416
}

Debugging1/homework/bug2.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
This programs should log all the top ten movies except the first three.
3+
Then it should log all top ten actors except the first three.
4+
*/
5+
6+
let top10Movies = [
7+
'AI',
8+
'Shawshank Redemption',
9+
'Godfather',
10+
'Pulp Fiction',
11+
'Fight Club',
12+
'Forrest Gump',
13+
'Inception',
14+
'Goodfellas',
15+
'The Matrix',
16+
'Interstellar'];
17+
18+
let top10Actors = [
19+
'Marlon Brando',
20+
'Jack Nickolson',
21+
'Robert De Niro',
22+
'Al Pacino',
23+
'Daniel Day-Lewis',
24+
'Dustin Hoffman',
25+
'Tom Hanks',
26+
'Anthony Hopkins',
27+
'Paul Newman',
28+
'Denzel Washington'];
29+
30+
let index = 3;
31+
for (index; index < top10Movies.length; index++) {
32+
let movie = top10Movies[index];
33+
console.log('Top 10 movie: ' + movie);
34+
}
35+
36+
for (index; index < top10Actors.length; index++) {
37+
let actor = top10Actors[index];
38+
console.log('Top 10 actor: ' + actor);
39+
}

Debugging1/homework/bug3.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
For each hour our train hasn't arrived this program should log `train arriving
3+
in n hours`. Where n is the number of hours it takes for the train to arrive.
4+
Like:
5+
train arrives in 9 hours
6+
train arrives in 8 hours
7+
train arrives in 7 hours
8+
etc..
9+
*/
10+
11+
let currentHour = 0;
12+
let trainArrivesHour = 9;
13+
14+
for(let hour = currentHour; currentHour <= trainArrivesHour; hour++) {
15+
let trainArrivesIn = trainArrivesHour - hour;
16+
console.log("train arrives in " + trainArrivesIn + " hours");
17+
}

Debugging2/LECTURE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Debugging 2
2+
3+
## Examples
4+
5+
Work through some examples and/or homework assignments together with the
6+
students.
7+
8+
## Creating variables
9+
10+
Inlining is great but not when debugging.
11+
12+
TODO Explain how to extract function call results into variables and why that is
13+
useful.
14+
15+
## ESLint
16+
17+
TODO
18+
19+
## Simplifying input
20+
21+
Often a program is big, and the defect not obvious. The program fails but you
22+
have no clue where to start because the program state is too big to reason
23+
about. Instead of frantically using `console.log` everywhere (which might
24+
sometimes work) we take one step back. We first simplify the input so that we
25+
get to a manageable state, something we can reason about. If our program still
26+
fails we can continue debugging. If it doesn't we need to pick different input.
27+
28+
*TODO Write a buggy program that uses a lots of input and state.*
29+
30+
- Maybe a sorting algorithm?
31+
- Something that uses a stack
32+
- Filtering algorithm (something that filters on a certain string)

0 commit comments

Comments
 (0)