Commenting Flashcards

1
Q

What is the importance of commenting within a method?

A

Commenting within a method is important to improve code readability and to help other programmers understand the purpose and functionality of the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In what parts of a method should you consider adding comments?

A

You should consider adding comments to the variable declarations, branching structures (if-, switch-statements), and loops (while-, do-, for-statements).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is it important to comment on variable declarations?

A

It is important to comment on variable declarations to provide information about the type of variable and its purpose in the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why is it important to comment on branching structures and loops?

A

: It is important to comment on branching structures and loops to explain the logic and flow of the code and to highlight any specific conditions or scenarios that are being checked.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the benefit of commenting on a program structure?

A

Commenting on a program structure helps to improve the code’s readability and maintainability by allowing other programmers to quickly understand the purpose and functionality of the code without having to read through every line of the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Examples of Variable declarations

A

[] int p //polynomial
int i,j //counters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you comment branching

A

State the purpose of the whole branching structure, explain what happens in each of the cases

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Example of comments in branches

A

//add polynomials only if they are of the same degree
If degree(p) = degree(q){
then // add polynomials
{…}
else //error case
{…}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you comment loops

A

State the purpose of the whole loop structure, explaining how the computation takes, place, discuss termination of the loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Example of commenting in loops

A

/* evaluate the polynomial p
Implements Horner’s Method
Terminates as k is not touched in the loop body and k is initialised to a positive value
*/
b = p[n]
for (k = degree(p); k >= 0; k = k - 1) {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is something to avoid

A

Over-commenting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly