Code Refactoring Flashcards

(10 cards)

1
Q

What is refactoring and why is it beneficial?

A

An activity by which we modify code but don’t change its functionality. Generally, the purpose of refactoring is to improve readability / understandability or reduce the number of lines of code which is ultimately done to simplify future code changes and reduce the amount of code that has to be maintained.

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

What is meant by “code smells”?

A

This is a term used to describe indications of bad design or bad internal quality in code.

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

What should be refactored?

A
  • Code smells (since they’re an indication of bad design)
  • Code that is hard to read or hard to understand
  • Code that does not adhere to conventions
  • Code that is unnecessary or in the wrong place
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the most common code smell?

A

Duplicate code! Two techniques to eliminate duplicate code are extract method and extract superclass.

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

Extract method

A

​A refactoring pattern used to address duplicate code in which we pull out, or extract, the code that’s duplicated and put it in a new method. Then that method is invoked wherever the code was previously duplicated.

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

Extract superclass

A

A refactoring pattern in which a new common superclass is created to contain methods that were previously duplicated across classes. This way the code can be written once in the superclass and then used in multiple subclasses.

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

Dictionary words

A

Words that occur in everyday language. These are good to use as variable names, as they tend to be easier to read / recognize in comparison to words that are made up.

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

Syntactic purpose

A

​For a given token, this is it’s function in that particular position in the statement of code.

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

What are the 4 primary factors that impact code readability?

A

Code readability​ is the ease with which the reader can identify and differentiate tokens and their syntactic purpose. It is important because people need to read code in order to fix bugs, add features, etc. A few of the primary ways to improve readability include:

  1. Use of whitespace
  2. Identifier length
  3. Use of dictionary words
  4. Variation among identifiers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the 4 primary factors that impact code understandability?

A

Code understandability ​is the ease with which a reader can identify the semantic meaning of code. A few of the primary ways it can be improved include:

  1. Use meaningful identifier names
  2. Use indentation and spacing
  3. Use comments
  4. Use punctuation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly