Skip to content

Commit af3b790

Browse files
committed
reply to dan's comments
1 parent ba7cb3f commit af3b790

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

app/pages/learn/01_tutorial/08_more-resources/02_debugging.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ subheader_select: tutorials
99
main_css_id: learn
1010
toc:
1111
- What is debugging? {intro}
12-
- Why not println {println}
13-
- Why not unit testing {unit}
12+
- Why not println? {println}
13+
- Why not unit testing? {unit}
1414
- What is a breakpoint? {breakpoint}
1515
- How can debuggers be used? {usage}
1616
- Debugger basics {basic}
@@ -31,26 +31,26 @@ You might be wondering why it is called "debugging". The term became popular in
3131
A debugger is a tool in your IDE (integrated development environment) that lets you see the values of different variables at different points in the program. It's like a really powerful magnifying glass. While a few details vary between Eclipse/IntelliJ/NetBeans/VS Code, the concepts are the same.
3232

3333
<a id="println">&nbsp;</a>
34-
## Why not Println
34+
## Why not Println?
3535

3636
When first learning how to code, we often write code like this to see what is going on:
3737

3838
```java
3939
System.out.println(numCats);
4040
```
4141

42-
There's nothing wrong with using println (as long as you don't commit it). However, it can quickly get unmanagable in a more complicated program especally if you have multiple things to keep track of or a lot of loops. It can also be hard to find when there is a lot of logging in the application. (I used the stars and my initials to mitigate that, but still can get past the point where println is useful.)
42+
There's nothing wrong with using `println` (as long as you don't commit it). However, it can quickly get unmanagable in a more complicated program especally if you have multiple things to keep track of or a lot of loops. It can also be hard to find when there is a lot of logging in the application. (I used the stars and my initials to mitigate that, but still can get past the point where println is useful.)
4343

4444
```java
4545
System.out.println("*** JB i=%s numCats=%s numDogs=%s".formatted(i, numCats, numDogs));
4646
```
4747

48-
Even if println() does meet your needs at the moment, it won't forever. Learning how to use a debugger helps avoid the problem that you use println just because it is all you know.
48+
Even if `println()` does meet your needs at the moment, it won't forever. Learning how to use a debugger helps avoid the problem that you use println just because it is all you know.
4949

5050
<a id="unit">&nbsp;</a>
51-
## Why not unit testing
51+
## Why not unit testing?
5252

53-
Nothing is wrong with unit testing. Unit tests are great. They document expected behavior. They tell you if an unexpected value is returned. They help you understand the behavior of the code. And sometimes they can even give you big clues about what is wrong with the code. However, they don't tell you what is happening inside the broken code when it isn't returning the right value. For that, you use a debugger with the unit test to see what is going on inside the method.
53+
Nothing is wrong with unit testing. Unit tests are great. They document expected behavior. They tell you if an unexpected value is returned. They help you understand the behavior of the code. And sometimes they can even give you big clues about what is wrong with the code. However, they don't tell you what is happening inside the broken code when it isn't returning the right value. For that, you use a debugger with the unit test to see what is going on inside the method. And once you fix your code, unit tests can help catch new bugs from being introduced!
5454

5555
```java
5656
@Test
@@ -62,7 +62,7 @@ void magic() {
6262
<a id="breakpoint">&nbsp;</a>
6363
## What is a breakpoint?
6464

65-
I've (improperly) implemented the magic method. It's supposed to multiply six times seven and get 42. However, that's not what happens. After (not) much investigation, I am baffled and realize I want to know what the values of part1 and part2 are on line 5.
65+
I've (improperly) implemented the magic method. It's supposed to multiply six times seven and get 42. However, that's not what happens. After (not) much investigation, I am baffled and realize I want to know what the values of `part1` and `part2` are on line 5.
6666

6767
That's what a breakpoint is for. It lets me tell the debugger to pause the program there and let me poke around.
6868

@@ -84,13 +84,13 @@ When the debugger stops on line 5, I see that part2 is the seven that I expected
8484
There are a number of reasons why you might want to use a debugger. Three of the most common are:
8585

8686
1. Fixing broken code - The debugger allows you to see the values of variables as the code runs. This allows you to see where it stops behaving as expected.
87-
2. Understanding unfamiliar code - Seeing the values as the code runs can help you undersatnd in better
87+
2. Understanding unfamiliar code - Seeing the values as the code runs can help you understand it better
8888
3. Tracing the path of the code - When stopping at a breakpoint, the debugger shows what classes/methods were called in order to get there. You can even click on them to see what the variables in scope at those points are.
8989

9090
<a id="basic">&nbsp;</a>
9191
## Debugger Basics
9292

93-
There are four basic debugger commands to control the flow of execution once the debugger stops at your first breakpoint. For each of these commands, we will use the Flow class as an example.
93+
There are four basic debugger commands to control the flow of execution once the debugger stops at your first breakpoint. For each of these commands, we will use the `Flow` class as an example.
9494

9595
```java
9696
public class Flow {
@@ -112,7 +112,7 @@ public class Flow {
112112
```
113113

114114
1. Step into - Tells the program to execute, but only to the first line of the method call. Suppose I have a breakpoint on line 7. When I tell the debugger to "step into", it goes to line 13.
115-
2. Step over - Tells the program to execute but not stop in any methods. If I have a breakpoint on line 7 and tell the debugger to 'step over", the debugger will then be on line 8. Choosing "step over" again will bring the debugger to line 9.
115+
2. Step over - Tells the program to execute but not stop in any methods. If I have a breakpoint on line 7 and tell the debugger to "step over", the debugger will then be on line 8. Choosing "step over" again will bring the debugger to line 9.
116116
3. Step out/return - Tells the program to run to the end of the method and go back to the caller. If I have a breakpoint on line 13 and choose "step out" or "step return", the debugger will be on line 7 with the result from the method call. (Step out and step return are the same thing. Different IDEs use different names.)
117117
4. Resume - Tells the program to keep going until it hits another breakpoint or completes.
118118

@@ -123,7 +123,7 @@ Debuggers have many advanced techniques. Three common ones are:
123123

124124
1. Conditional breakpoint - Normally, the debugger stops where you asked for a breakpoint. If you are in a loop or have a clue what values trigger the problem, you don't want that. A conditional breakpoint allows you to add a bit of Java code to your breakpoint so it will only stop when that condition is true. This approach avoids having to hit resume a lot of times until you get to the value you care about.
125125
2. Evaluation - Once you get to your breakpoint, you can write Java code to determine the state of affairs. For example, you can call methods on the available variables.
126-
3. Hot replacement - You can manually change the value of a variable in the debugger and let the code continue to run. It will use your new, corrected value instead of the original one. This lets you explore the impact of a potential fix.
126+
3. Hot replacement - You can manually change the value of a variable in the debugger and let the code continue to run. It will use your new, updated value instead of the original one. This lets you explore the impact of a potential fix.
127127

128128
<a id="docs">&nbsp;</a>
129129
## Documentation

0 commit comments

Comments
 (0)