Skip to content

Commit f28ae71

Browse files
author
Frank Versnel
committed
Added analogies for the defect, infection, failure terms.
1 parent f55a26e commit f28ae71

1 file changed

Lines changed: 25 additions & 23 deletions

File tree

‎lecture1.md‎

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Introduction
22

3-
Nobody writes programs that are correct the first time around. Today we'll be
4-
talking about debugging: techniques for finding and fixing bugs in your code.
5-
3+
Nobody writes programs that are correct the first time around. Today we'll learn
4+
about debugging: techniques and tools for finding and fixing bugs in your code.
65
In your career as a programmer you will discover and fix many bugs and you will
76
debug code by other programmers. Throughout the entire curriculum you will get
87
homework/exercises that requires you to fix buggy programs.
@@ -11,17 +10,20 @@ So what is a bug? A bug lets a program do something it was not intended to do.
1110
But that definition is rather vague. Let's break it down. Actually a bug consist
1211
of three distinct parts:
1312

14-
1. a **defect** - a piece of code that can cause an infection
15-
2. an **infection** - a program state that is different from the programmer's intention.
16-
3. a **failure** - externally observable effect of faulty program behavior caused by the
17-
infection.
18-
19-
*TODO To help with the language barrier we first explain the English meaning of
20-
*the words defect, infection, and failure.*
13+
1. A **defect** - a piece of code that can cause an infection.<br/>
14+
*We can think of a **defect** as the source of a disease.*
15+
2. An **infection** - a program state that is different from the programmer's
16+
intention.<br/>
17+
*From the source an **infection** takes place. Someone will take ill and in turn
18+
that person will make more and more people ill.*
19+
3. A **failure** - externally observable effect of faulty program behavior
20+
caused by the infection.<br/>
21+
*When we notice someone took ill we know that there has been an infection and
22+
that there must have been a source somewhere.*
2123

2224
# Hello wordl
2325

24-
Let's look at this program. It has a bug in it:
26+
Let's look at this program. It has a defect in it:
2527

2628
```javascript
2729
// This program should print:
@@ -40,10 +42,10 @@ console.log(result);
4042
Debugging always starts by reading either some error message or look at
4143
something you didn't expect. Now, what a lot of people do is throw their hands
4244
in the air and say: "aahhhh, it's not working!". Don't do that. Something is not
43-
working, you don't know what, but you're gonna find out. Most likely most of your
44-
code is perfectly fine, but you just made a mistake somewhere. Reading the error
45-
is the absolute first step and the first clue to where your defect might be
46-
hiding.
45+
working, you don't know what, but you're gonna find out. Most likely most of
46+
your code is perfectly fine, but you just made a mistake somewhere. Reading the
47+
error is the absolute first step and the first clue to where your defect might
48+
be hiding.
4749

4850
You have to detach yourself from your code, because your code is wrong. Instead
4951
you need to rely on the solution of the problem you have in your head.
@@ -66,11 +68,11 @@ i++;
6668
contents.)
6769

6870
Remember that a defect will always result in an undesirable program state. So we
69-
need to look at our state to understand our program. To do this we add a
71+
need to look at our state to understand our bug. To do this we add a
7072
`console.log` line to our code where we let the program write down our state
7173
every time we do a lookup in the `elements` array. Our state is `i` and
72-
`elements`. I don't log `result` because `result` is derived from `i` and
73-
`elements` and I assume my defect is not in the lines `result += elements[i]`
74+
`elements`. We don't log `result` because `result` is derived from `i` and
75+
`elements` and we assume the defect is not in the lines `result += elements[i]`
7476
nor in `console.log(result)`. The defect must be somewhere before these lines.
7577

7678
```javascript
@@ -85,12 +87,12 @@ result += elements[i];
8587
"index i: 3 element: undefined"
8688
```
8789

88-
We see that at index `3` we do a lookup in our `elements` array the element is
89-
not there. `i++` is where the infection happens as a result of our defect,
90-
whatever that may be.
90+
We see that at index `3` when we do a lookup in our `elements` array the element
91+
is not there and javascript gives us the `undefined` value. So `i++` is where
92+
the infection happens as a result of our defect, whatever the defect may be.
9193

92-
Then `result += elements[i]` is where our initial infection of `i++` spreads
93-
into the `result` and now `result` is infected too.
94+
Then `result += elements[i]` is where our the infected `i` spreads into the
95+
`result` and now `result` is infected too.
9496

9597
## Defects
9698

0 commit comments

Comments
 (0)