Chapter 9 - Refactoring Flashcards

1
Q

Lehman’s Laws

A

a set of empirical laws concerning aging, internal quality, and the evolution of software systems

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

refactoring

A

code transformations that improve a system’s maintainability without affecting its behavior

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

Extract Method

A

aims to extract a piece of code from method f and move it to a new method g.

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

Inline Method

A

This refactoring operates in the opposite direction of method extraction. Consider a method with only one or two lines of code that is rarely called. Thus, the benefits offered by this method, both in terms of reuse and organization of the code, are minimal. Consequently, it can be removed from the system, and its body can be incorporated into the call sites.

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

Move Method

A

This occurs when a method f is located in a class A, but it uses more services from class B. For instance, it may have more dependencies on elements of B than on elements of its original class. In such cases, moving f to B should be considered. This refactoring can improve the cohesion of A, reduce the coupling between A and B, and ultimately make both classes easier to understand and modify.

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

Pull Up Method

A

when we move a method from a subclass to a superclass

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

Push Down Method

A

when a method is moved down the class hierarchy

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

Renaming

A

giving a more appropriate and meaningful name to a code element.

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

Deprecation

A

a mechanism provided by programming languages to indicate that a code element is outdated and, therefore, should not be used anymore. When the compiler detects a piece of code using a deprecated element, it issues a warning.

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

Extract Variable

A

used to simplify expressions and make them easier to read and understand

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

Remove Flag

A

a refactoring that recommends using statements like break or return, instead of control variables (or flags).

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

Remove Dead Code

A

recommends deleting methods, classes, variables, or attributes that are no longer used

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

Opportunistic refactorings

A

carried out during a programming task when we discover that a piece of code is not well implemented and can be improved

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

planned refactorings

A

typically involve time-consuming and complex changes that cannot be accommodated within a typical development task. Instead, they should be carried out in scheduled and dedicated sessions.

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

Automated Refactorings

A

most IDEs provide support to automate refactorings in the following manner: developers select the block of code they intend to refactor and choose the refactoring operation they wish to perform. The IDE then performs this operation automatically.

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

preconditions

A

whether the refactoring will not result in a compilation error or change the program’s behavior

17
Q

bad smells

A

indicators of low-quality code, that is, code that is difficult to maintain, understand, modify, or test.

18
Q

Code duplication

A

a common code smell and one of those with the highest potential to harm the evolution of a system. Duplicated code increases maintenance effort, as changes need to be applied to more than one part of the code.

19
Q

clones

A

Blocks of duplicated code

20
Q

Long Method

A

considered a code smell, as they make the code harder to understand and maintain.

21
Q

Large Class

A

classes shouldn’t assume multiple responsibilities or provide services that aren’t cohesive. Considered a smell because they make the code harder to understand and maintain. These classes are also more challenging to reuse in another package or system. Large classes are characterized by a large number of attributes with low cohesion among them.

22
Q

God Class or a Blob

A

When a class grows so much that it starts to monopolize most of the system’s intelligence

23
Q

Feature Envy

A

This smell corresponds to a method that seems to envy the data and methods of another class. In other words, it accesses more attributes and methods of class B than of its current class A.

24
Q

Long Parameters List

A

In addition to being small, methods should, whenever possible, have few parameters. That is, a Long Parameters List is a smell that can be eliminated in two main ways. First, we should check whether one of the parameters can be obtained directly by the called method. Another possibility is to create a class to group some of the parameters

25
Q

Global Variables

A

should be avoided, as they result in a poor type of coupling. For this reason, they are considered a code smell. Essentially, global variables make it more difficult to understand a function without looking at other parts of the system.

26
Q

Primitive Obsession

A

This code smell occurs when primitive types (that is, int, float, String, etc.) are used instead of specific classes.

27
Q

Mutable Objects

A

one whose state can be modified after creation

28
Q

Data Classes

A

These classes contain only attributes and no methods, or at most, they have getters and setters.

29
Q

Comments

A

the idea is that comments should not be used to explain bad code. Instead, we should refactor the code, thereby improving readability. After doing that, there’s a good chance that the comments will become redundant

30
Q

Technical deb

A

technical problems that can hinder the maintenance and evolution of a system. These problems include, among others, lack of tests, architectural issues, systems with many code smells, and systems without any documentation at all.