Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AB3: Tracing Code] Add more headers to section instructions #42

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cb71de9
Edit LogicSequenceDiagram puml to show exact arguments
UdhayaShan1 Jul 7, 2024
6d49bce
Fix LogicSequenceDiagram by showing creation of parser
UdhayaShan1 Jul 7, 2024
16abf00
Add new edit sequence puml with MainWindow and model for future use
UdhayaShan1 Jul 7, 2024
ec55e13
Update tracingcode.md with h3 css style added
UdhayaShan1 Jul 7, 2024
005583c
Merge branch 'master' into tracing-code-add-headers
UdhayaShan1 Jul 7, 2024
464e91a
Edit arguments
UdhayaShan1 Jul 8, 2024
5ad51a5
Fix EditSequenceDiagramWithMainWindow png and remove html anchor
UdhayaShan1 Jul 13, 2024
9212c14
Edit LogicSequence puml to show execution and add annotated images
UdhayaShan1 Jul 13, 2024
a65f636
Add a logic sequence diagram only with mainwindow and logicmanager
UdhayaShan1 Jul 13, 2024
9f8f897
Add remaining headers and diagrams
UdhayaShan1 Jul 13, 2024
2990596
Update image
UdhayaShan1 Jul 13, 2024
4cfab7b
Merge branch 'master' into tracing-code-add-headers
UdhayaShan1 Jul 27, 2024
8fb8f61
Remove redundant lines and custom css
UdhayaShan1 Jul 27, 2024
5fc1be6
Updated tracing code high level sequence diagram description
UdhayaShan1 Jul 27, 2024
da6ae49
Removed MainWindow from puml to not overlap components
UdhayaShan1 Jul 27, 2024
3327fde
Misc change
UdhayaShan1 Jul 27, 2024
122ca7d
Add double quotes for puml method call arguments
UdhayaShan1 Jul 27, 2024
42c96b5
Add label content and change label names to "T<no>" in bold
UdhayaShan1 Jul 27, 2024
66cca5e
Making spacing consistent
UdhayaShan1 Jul 27, 2024
451b0fe
Update label content to be clearer
UdhayaShan1 Jul 27, 2024
e5e4331
Remove unnecessary spacing and fix typos
UdhayaShan1 Jul 27, 2024
e7db74d
Merge branch 'master' into tracing-code-add-headers
UdhayaShan1 Jul 27, 2024
ba92d2f
Added deletion to puml and misc change
UdhayaShan1 Jul 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 66 additions & 6 deletions tutorials/ab3TracingCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ pageNav: 3

# {{ title }}


<link rel="stylesheet" href="images/tracing/static/tracing.css">
UdhayaShan1 marked this conversation as resolved.
Show resolved Hide resolved
> Indeed, the ratio of time spent reading versus writing is well over 10 to 1. We are constantly reading old code as part of the effort to write new code. …[Therefore,] making it easy to read makes it easier to write.
>
> — Robert C. Martin Clean Code: A Handbook of Agile Software Craftsmanship

When trying to understand an unfamiliar code base, one common strategy used is to trace some representative execution path through the code base. One easy way to trace an execution path is to use a debugger to step through the code. In this tutorial, you will be using the IntelliJ IDEA’s debugger to trace the execution path of a specific user command.


## Before we start
<h2 id="before-we-start">Before we start</h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need. The anchor before-we-start is automatically generated by MarkBind. However, MarkBind will also warn about non-existent hash, which is a bug. Can ignore that for now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted


Before we jump into the code, it is useful to get an idea of the overall structure and the high-level behavior of the application. This is provided in the 'Architecture' section of the developer guide. In particular, the architecture diagram (reproduced below), tells us that the App consists of several components.

<pic src="https://se-education.org/addressbook-level3/images/ArchitectureDiagram.png" alt="ArchitectureDiagram" />

It also has a sequence diagram (reproduced below) that tells us how a command propagates through the App.
It also has a sequence diagram (reproduced below)
that tells us how a command propagates through the App.
UdhayaShan1 marked this conversation as resolved.
Show resolved Hide resolved

<pic src="https://se-education.org/addressbook-level3/images/ArchitectureSequenceDiagram.png" width="550" />

Expand Down Expand Up @@ -88,15 +89,44 @@ Bingo\! `MainWindow#executeCommand()` seems to be exactly what we’re looking f
Now let’s set the breakpoint. First, double-click the item to reach the corresponding code. Once there, click on the left gutter to set a breakpoint, as shown below.
![LeftGutter](images/tracing/LeftGutter.png)


UdhayaShan1 marked this conversation as resolved.
Show resolved Hide resolved
## Tracing the execution path

Recall from the User Guide that the `edit` command has the format: `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [t/TAG]…` For this tutorial we will be issuing the command `edit 1 n/Alice Yeoh`.
At this point, you should have appreciated the general sequence diagram **shown** [above](#before-we-start)


For this code tracing,
we will explore the `EditCommand` which is a feature that allows users to edit exising person fields in AB3.

<box type="tip" seamless>
Recall from the <a href="https://se-education.org/addressbook-level3/UserGuide.html#editing-a-person--edit">User Guide</a> that the <code>edit</code> command has the format: <code>edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [t/TAG]…</code>.
</box>

For this tutorial, we will be issuing the command <code>edit 1 n/Alice Yeoh</code>

Specifically,
we trace the following sequence diagram
which explores the `Logic` component in more detail which will be paramount to understanding other commands as well!

<puml src="images/tracing/LogicSequenceDiagramWithMainWindow.puml" alt="Tracing an `edit` command with specific arguments"></puml>
UdhayaShan1 marked this conversation as resolved.
Show resolved Hide resolved


<box type="tip" seamless>

**Tip:** Over the course of the debugging session, you will encounter every major component in the application. Try to keep track of what happens inside the component and where the execution transfers to another component.
</box>





UdhayaShan1 marked this conversation as resolved.
Show resolved Hide resolved
### 1. MainWindow -> LogicManager

<annotate src="images/tracing/LogicSequenceDiagramWithMainWindow.png" width="900" alt="Sample Image">
<!-- Set Legend to both -->
<a-point x="26%" y="20%" label="1"/>
</annotate>

1. To start the debugging session, simply `Run` \> `Debug Main`

1. When the GUI appears, enter `edit 1 n/Alice Yeoh` into the command box and press `Enter`.
Expand All @@ -111,7 +141,17 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [
1. We are interested in the `logic.execute(commandText)` portion of that line so let’s _Step in_ into that method call:<br>
![StepInto](images/tracing/StepInto.png)

1. We end up in `LogicManager#execute()` (not `Logic#execute` -- but this is expected because we know the `execute()` method in the `Logic` interface is actually implemented by the `LogicManager` class). Let’s take a look at the body of the method. Given below is the same code, with additional explanatory comments.
### 2. LogicManager -> AddressBookParser

<annotate src="images/tracing/LogicSequenceDiagramWithMainWindow.png" width="900" alt="Sample Image">
<!-- Set Legend to both -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<!-- Set Legend to both -->

Also update the alt property

<a-point x="50.7%" y="29%" label="2"/>
</annotate>


1. After stepping in, we note that `MainWindow` has passed control to the `Logic` component.

1. Specifically, We end up in `LogicManager#execute()` (not `Logic#execute` -- but this is expected because we know the `execute()` method in the `Logic` interface is actually implemented by the `LogicManager` class). Let’s take a look at the body of the method. Given below is the same code, with additional explanatory comments.
UdhayaShan1 marked this conversation as resolved.
Show resolved Hide resolved

**LogicManager\#execute().**

Expand Down Expand Up @@ -146,7 +186,8 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [
1. _Step over_ the logging code since it is of no interest to us now.
![StepOver](images/tracing/StepOver.png)

1. _Step into_ the line where user input is parsed from a String to a Command, which should bring you to the `AddressBookParser#parseCommand()` method (partial code given below):
1. _Step into_ the line where user input in parsed from a String to a Command, which should bring you to the `AddressBookParser#parseCommand()` method (partial code given below):
UdhayaShan1 marked this conversation as resolved.
Show resolved Hide resolved

```java
public Command parseCommand(String userInput) throws ParseException {
...
Expand All @@ -155,6 +196,18 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [
...
```

<h3 id="flow-3">3. AddressBookParser -> EditCommandParser</h3>


<annotate src="images/tracing/LogicSequenceDiagramWithMainWindow.png" width="900" alt="Sample Image">
<!-- Set Legend to both -->
<a-point x="60.7%" y="30%" label="3"/>
<a-point x="69%" y="53%" label="4"/>
</annotate>


1. Now, `LogicManager` has passed control to `AddressBookParser`

1. _Step over_ the statements in that method until you reach the `switch` statement. The 'Variables' window now shows the value of both `commandWord` and `arguments`:<br>
![Variables](images/tracing/Variables.png)

Expand All @@ -169,6 +222,13 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [
...
```

1. Note that this creates the `EditCommandParser` first.


### 4. AddressBookParser -> EditCommand

1. `AddressBookParser` calling `parse(...)` of the newly created `EditCommandParser`. This is shown in the diagram [earlier when EditCommand was created](#flow-3).

1. Let’s see what `EditCommandParser#parse()` does by stepping into it. You might have to click the 'step into' button multiple times here because there are two method calls in that statement: `EditCommandParser()` and `parse()`.

<box type="tip" seamless>
Expand Down
2 changes: 2 additions & 0 deletions tutorials/images/style.puml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
!define LOGIC_COLOR_T2 #6A6ADC
!define LOGIC_COLOR_T3 #1616B0
!define LOGIC_COLOR_T4 #101086
!define LOGIC_COLOR_T5 #adbc40

!define MODEL_COLOR #9D0012
!define MODEL_COLOR_T1 #F97181
!define MODEL_COLOR_T2 #E41F36
!define MODEL_COLOR_T3 #7B000E
!define MODEL_COLOR_T4 #51000A
!define MODEL_COLOR_T5 #c6d4c0

!define STORAGE_COLOR #A38300
!define STORAGE_COLOR_T1 #FFE374
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have these png file in the repo. MarkBind will generate it automatically from the puml file with the same name.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions tutorials/images/tracing/EditSequenceDiagramWithMainWindow.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@startuml
!include ../style.puml
skinparam ArrowFontStyle plain

box Ui MODEL_COLOR_T5
participant "m:MainWindow" as MainWindow LOGIC_COLOR_T5

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant ":EditCommandParser" as EditCommandParser LOGIC_COLOR
participant "d:EditCommand" as EditCommand LOGIC_COLOR
participant "r:CommandResult" as CommandResult LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant "m:Model" as Model MODEL_COLOR
end box



--> MainWindow
activate MainWindow
MainWindow -> LogicManager : execute("edit 1 n/Alice Yeoh")
activate LogicManager

LogicManager -> AddressBookParser : parseCommand("edit 1 n/Alice Yeoh")
activate AddressBookParser

create EditCommandParser
AddressBookParser -> EditCommandParser
activate EditCommandParser

EditCommandParser --> AddressBookParser
deactivate EditCommandParser

AddressBookParser -> EditCommandParser : parse("1 n/Alice Yeoh")
activate EditCommandParser

create EditCommand
EditCommandParser -> EditCommand
activate EditCommand

EditCommand --> EditCommandParser :
deactivate EditCommand

EditCommandParser --> AddressBookParser : d
deactivate EditCommandParser
'Hidden arrow to position the destroy marker below the end of the activation bar.
EditCommandParser -[hidden]-> AddressBookParser
destroy EditCommandParser

AddressBookParser --> LogicManager : d
deactivate AddressBookParser

LogicManager -> EditCommand : execute(m)
activate EditCommand

EditCommand -> Model : ...
activate Model

Model --> EditCommand
deactivate Model

create CommandResult
EditCommand -> CommandResult
activate CommandResult

CommandResult --> EditCommand
deactivate CommandResult

EditCommand --> LogicManager : r
deactivate EditCommand

LogicManager --> MainWindow
deactivate LogicManager

[<-- MainWindow
deactivate MainWindow
@enduml
Binary file added tutorials/images/tracing/LogicSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions tutorials/images/tracing/LogicSequenceDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ Participant "command:EditCommand" as ec LOGIC_COLOR

[-> logic : execute
activate logic
logic -> abp ++: parseCommand(commandText)
logic -> abp ++: parseCommand(edit 1 n/Alice Yeoh)
create ecp
abp -> ecp
abp -> ecp ++: parse(arguments)
activate ecp
ecp -> abp
deactivate ecp
abp -> ecp ++: parse(1 n/Alice Yeoh)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
abp -> ecp ++: parse(1 n/Alice Yeoh)
abp -> ecp ++: parse("1 n/Alice Yeoh")

Check other places as well.

create ec
ecp -> ec ++: index, editPersonDescriptor
ecp -> ec ++: 1, n/Alice Yeoh
ec --> ecp --
ecp --> abp --: command
abp --> logic --: command
[<-- logic

@enduml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions tutorials/images/tracing/LogicSequenceDiagramWithMainWindow.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@startuml
!include ../style.puml
skinparam ArrowFontStyle plain

Participant ":MainWindow" as main LOGIC_COLOR
Participant ":LogicManager" as logic LOGIC_COLOR
Participant ":AddressBookParser" as abp LOGIC_COLOR
Participant ":EditCommandParser" as ecp LOGIC_COLOR
Participant "command:EditCommand" as ec LOGIC_COLOR

main -> logic : execute(edit 1 n/Alice Yeoh)
activate logic
logic -> abp ++: parseCommand(edit 1 n/Alice Yeoh)
create ecp
abp -> ecp
activate ecp
ecp -> abp
deactivate ecp
abp -> ecp ++: parse(1 n/Alice Yeoh)
create ec
ecp -> ec ++: 1, editPersonDescriptor
ec --> ecp --
ecp --> abp --: command
abp --> logic --: command
logic --> main --: command

@enduml
6 changes: 6 additions & 0 deletions tutorials/images/tracing/static/tracing.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* custom.css */
h3 {
color: #ff6347;
padding: 10px;
border-radius: 5px;
}