L14: Avoiding the "Bad" Flashcards

1
Q

Code, design, and architecture smells (or anti-patterns)

A

Bad software is describe sing the methaphor of smells
- Code smells: any property of code that can hint at deeper problems
- Design smells: design structures that violate a design principle
- Architecture smells: undesired structures in the software architecture

Just symptoms, not defects by themselves!
Related, subjective, language/methodology-dependent, and overlapping

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

Technical debt (or design/code debt)

A

Metaphor for future rework needed due to poor software design/code
- Describes impact of poor software design (e.g. software smells)
- Can get worse over time (accumulates interest)
- Increases costs of implementing future changes (or makes future changes necessary)

Essentially:
- Long-term negative consequences of poor design…
- …that was motivated by short-term benefits

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

What causes technical debt?

A
  • Deadlines
  • Inappropriate planning
  • Lack of well-defined processes
  • Not adopting best practices
  • Experience, knowledge, …
  • Outdated/incomplete documentation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the consequences to technical debt?

A
  • Low software quality
  • Delays
  • Low maintainability
  • Rework
  • Financial loss
  • Dissatisfaction (team, stakeholders, …)
  • Inadequate document
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Refactoring

A
  • Changes to a software’s internal structure…
  • …to make it easier to comprehend, maintain, and modify …
  • … without changing its (observable) behavior (so, fixing a bug, is not a refactoring, since it changes behavior)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Large and long/complex method

A

Properly abstracted methods/classes start small but often grow over time

Developers add new concerns to existing ones (i.e. do not separate concerns properly)
- Longer methods/classes are harder to understand
- May hide duplicate code and/or specific behavior

Closely related to “Spaghetti code” (code without a structure that is hard to maintain and comprehend)

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

What to do about the blob or god class?

A
  • Separate concerns
  • Extract classes/methods
  • Introduce inheritance
  • Separate into MVC
  • Define interfaces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

God class or the blob

A

A large (previous smell) class acts as controller of many data classes

Defines all functionalities and decisions (violating: separation of concerns, cohesion and coupling, single responsibility principle)

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

Long parameter list and what to do?

A
  • Methods with too “many” parameters
  • Merging different algorithms and controlling them via parameters
  • Can be challenging to understand and use

So what to do?
- Check whether parameters are needed
- Define reference types for passing data

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

Alternative class with different interface

A

Exchangeable classes provide different interfaces (public methods) (remember strategy design pattern)

Makes it
- Harder to understand code
- Impossible to exchange behavior

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

What to do about long parameter list and alternative class with different interface?

A
  • Following established design patterns and principles (strategy, template, abstract data types, …)
  • Renaming methods, changing parameters, …
  • Defining an inheritance hierarchy
  • Contracts, documentation, and communication
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Shotgun surgery and what to do?

A
  • Modifying any code requires changes to various classes
  • Violating single-responsibility as well as cohesion/coupling

What to do?
- Define proper software design
- Move methods or parameters
- Redefine units

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

Code clones or duplicate code

A

Code that occurs multiple times at different locations
- Copy and paste programming
- Clone and own development

Often used due to simplicity

Can lead to maintenance issues…
- Fixing bugs or updating each location
- Additional code
- Not properly separated

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

The problems of dealing with duplicated code

A

In the small (copy and paste):
- Identifying clones in a system (type 1 to type 4 clones)
- Deciding where to move a clone
- Duplicated abstractions
- Dealing with variations (e.g. template method)

In the large (clone and own):
- Merging long-living clones variants
- Redundant/new testing and features
- Identifying commonality and variations
- Expensive and time consuming

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

Dead code

A

Code that is (no longer) used or executed
- Unused variable
- Condition that is never reached
- Class that is not relevant/used anymore

Extensive support in modern IDEs (as far as identifiable considering the given visibility)

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

Feature envy

A

Methods rely more on data/behavior of another object than their own (often arises when moving data to different classes, but not the methods)

Careful with some design patterns (e.g. strategy)
- Purposefully separate data and behavior
- Aim to achieve a specific goal via this strategy (e.g. changing behavior dynamically)
- Still couple data and behavior (and keep it decoupled from other units)

16
Q

Cyclic hierarchy or dependencies

A
  • A supertype relies on one of its subtypes (inheritance)
  • 2 or more abstraction depend on each other, directly or indirectly
17
Q

Definitions of the following software smells: Middle man, Missing abstraction, Poltergeist

A
  • Middle man: A class has only the purpose of delegating to one other class
  • Missing abstraction: Using data clumps or strings instead of an abstract/reference type
  • Poltergeist: Classes with limited responsibility and short-lived objects (garbage collected right after creation)
18
Q

Software smells recap

A
  • Based on experiences and design principles
  • Subjective and interpretable
  • Perceived as symptoms for quality problems
  • Not defects