Lab 2 – Debugging
1. Name: Dhruv Nrupeshbhai Patel
2. [Link]
i. The cause of the defects that you found. (All the changes mentioned below are
shown in the Java file attached)
• When running the program, the result displayed shows the date from 0 instead
of beginning with 1. This defect is caused by the for loop that starts from 0
instead of 1. As the date begins from 1, the loop should begin from 1 for it to
print the entire set of dates for the month. It is also because the loop runs
through the value of ‘i <= days_to_print’ (underlined sign), that will print 8
days in the first line instead of 7 days.
• The calendar always started printing from February instead of January for any
year given. The reason this happened was due to the month that was set to 1 in
the loop. In case the month in the loop was set to 0 instead of 1, it would have
affected the dayofweek method where the value of ‘t’ in the return statement
would result in a negative value and given an error. I included a value of 0 for
it to ignore the first value and start displaying the month from January.
ii. The approach that let you locate the defect.
• I first looked carefully at the program to understand all the methods it had and
look at the working and functionality. I later ran the code to check the way the
output was displayed and noted down all the issues that I noticed.
• I used the tracing method to debug this code as it was a small program and had
a few formulae that needed to be investigated by substituting values in it. In
addition to that, I also created a breakpoint in the main function (line that
called the dayofweek function) to see the working and then stepped into the
function to see the functioning of the same for a given year.
• I analyzed the test cases using various values for the year and this gave me a
sense of what happened at every step. I compared the output with the calendar
for that year to check for the day.
• After tracing individual pieces of code, I looked at the correct logic for the
same and figured any constraints that would impact the other pieces of code
(editing the month in the loop would impact the dayofweek method).
• If in case the test case passed, I ran a few other extreme cases to ensure that
error and exception was handled (in case year less than 1800). Finally, after
the calendar was fixed, I finalized the same.
iii. The approximate amount of time it took you to locate the defect.
• I took approximately 10 minutes to read through the code, understand the
functions, and around 15-20 minutes to figure out the bugs in the code once I
ran the code. (Grateful to IntelliJ editor and debugger for helping me
throughout the debugging process).
iv. What strategy or strategies for debugging are most effective for you?
• Glancing and understanding the code is the utmost step for any debugging
process.
• Think of all the plausible test cases that could break the code.
• For the calendar code, I found an amalgamation of tracing and breakpoint
method very helpful. I find easier to debug code having formulae as it helps in
easier understanding of the logic.
• I usually check the code, see where it was breaking, go back, track, and solve
the error. This method was helpful.
• I faced slight issues understanding what the variables did due to improper
naming conventions given. However, diverting from the usual approach, I
renamed a few variables to see how it affected the values and code in general.
v. What makes them effective?
• Glancing through the code gives me an understanding, at least an overview of
what it does.
• The tracing method helps in shorter codes as it is easier to take an example and
debug.
• The breakpoint and step next and step in clearly state what happens exactly at
every step of the code so that we have a track of our code.
• Debugging tools helps in checking what each variable holds and how it effects
other parts of the code.
vi. For which conditions of the code will your strategies be effective of
ineffective?
• As stated earlier, tracing methods would be easier for shorter codes like this
one. In case it was a long code, tracing would not have been impossible, but it
would have been difficult to run through the code.
• Breakpoints and step in, step next usually helps in almost all types of codes as
the debugger helps a lot.
vii. How can a debugger support your strategies?
• Debugger was helpful while implementing the breakpoints and step in and step
next functions. IntelliJ’s ability to debug and provide step by step insights
about the code was helpful.
• It also helped me to check the code in detail, run specific pieces of code, and
check individual functions for errors.
• Isolating the code, fixing the same using the tool, and checking for
dependencies by using step in function assisted me a lot in the process.
3. [Link]
i. The cause of the defects that you found. (All the changes mentioned below are
shown in the Java file attached)
• The program consisted of 3 files – [Link], [Link], and
[Link]. When the [Link] program was run, the file never
gave the output as the function append and print had issues.
• The [Link] file had function named getWord(). However, when I ran the
function again, I could not find “word” as the setWord() function was never
created. This impacted the append function and the word was never appended
at the location.
ii. The approach that let you locate the defect.
• As usual, I looked at the program to ensure I understood the code first. I
wanted to see how the program behaved when it was run without changes to
look at the exceptions.
• The reason for the first error was that the IDE took Java functions for
LinkedList instead of the custom class LinkedList that was coded. This meant
that a package was to be created that would house the custom functions and
class created by the programmer. This solved the first part of the problem.
• Later, I looked at the point where I used breakpoints and backtracked the
program to see the place where append function had the issue. This function
had to append the word at the end of the list, and I saw that
[Link](new Node()) was created. However, the function to set the
word or place it in was not present. For the same, I created the setWord
function and passing the userWord to the word under the [Link] file. Once
the changes were made, I went and updated the append function under the
[Link] file. This solved the problem, and the code ran successfully.
iii. The approximate amount of time it took you to locate the defect.
• It took me more time than the previous problem. I took about 30-40 minutes to
see and figure out the main errors. The second part of the problem took a little
longer as I was unable to find the reason for the exception caused.
Backtracking from the exception took me slightly more time.
iv. What strategy or strategies for debugging are most effective for you?
• The strategies remained almost the same for both the problems. Glancing and
understanding the code helped me in my debugging process.
• Think of all the plausible test cases that could break the code.
• For the [Link] code, I found tracing and breakpoint method, and
step in and over functions very helpful.
• Backtracking was quite helpful this time.
v. What makes them effective?
• Looking at the code gives me a bird’s eye view of the program.
• The tracing method helped me in shorter codes snippets and functions as it
was easier to look at individual functions.
• The breakpoint and step in helped me take a detailed look at the function and
how it was called, and if anything was missing.
vi. For which conditions of the code will your strategies be effective of
ineffective?
• As I had never used breakpoint method earlier, and this lab was my first use of
breakpoint method, I believe that this is a powerful resource.
• I have always traced and backtracked, however, I used this method in addition
to breakpoint and step in methods to try out something new.
• Breakpoints and step in, step next usually helps in almost all types of codes.
vii. How can a debugger support your strategies?
• Debugger was helpful while implementing the breakpoints and step in and step
next functions. IntelliJ’s ability to debug and provide step by step insights
about the code was helpful.
• It also helped me to check the code in detail, run specific pieces of code, and
check individual functions for errors.
• I isolated the functions and ran specific function to know the error, fixing the
same using the tool, and checking for dependencies by using step in function
assisted me a lot in the process.