General Concepts in Code Writing Flashcards

(30 cards)

1
Q

Why clean code?

A
  • Code readability is a problem.
  • An unreadable code is hard to maintain.

“Code is clean if it can be understood easily –by
everyone on the team. With understandability comes
readability, changeability, extensibility and
maintainability…without accumulating up a large
amount of technical debt.”

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

According to Martin Fowler (2003), ______ is
metaphor by which “doing things the quick and dirty
way sets us up with a technical debt, which is similar to
a financial debt.”

A

technical debt

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

is a surface indication that usually
corresponds to a deeper problem in the system.

A

code smell

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

is a disciplined technique for restructuring
an existing body of code, altering its internal structure
without changing its external behavior.

A

Refactoring

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

In simple words, not writing the best implementation
from the very beginning may cost a lot in the latter
parts of the development.

A

Code rewriting!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • “A source code with a complex and tangled control
    structure” (Programming Lore).
  • Anti-pattern; difficult to understand and maintain
A

Spaghetti code

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

Code smells Examples

A

DLLC IUC LEP

  • Duplicated Code
  • Long Methods/Functions
  • Large Classes/Modules
  • Comments that indicate a code smell
  • Inconsistent Naming Conventions
  • Unused Code
  • Complex Conditionals
  • Lack of Error Handling
  • Excessive Nesting
  • Primitive Obsession
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

“When the same code is repeated in
multiple places, it can lead to maintenance problems
and increase the likelihood of introducing bugs”.

A

Duplicated Code

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

float area_of_triangle(float base, float height) {
return 0.5 * base * height;
}

float area_of_rectangle(float width, float height) {
return width * height;
}

float area_of_square(float side) {
return side * side;
}

A

Duplicated Code Sample

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

“Functions that are too long
can make it difficult to understand the code and can be
a sign that the function is doing too many things”.

A

Long Methods/Functions

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

“Similarly, large classes or
modules can make it difficult to understand the code
and can be a sign that the class/module is doing too
many things”.

A

Large Classes/Modules

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

“Sometimes,
developers leave comments in their code that indicate a problem that should be addressed”.

A

Comments that indicate a code smell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  • “Inconsistent
    naming of variables, functions, or classes can make it
    difficult to understand the code and can lead to
    confusion”.
A

Inconsistent Naming Conventions

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

“Code that is not being used should be
removed to avoid confusion and clutter”.

A

Unused Code

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

“Complex conditionals that are
difficult to read and understand can be a sign that the
logic is too convoluted and could be refactored for
clarity”.

A

Complex Conditionals

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

“Excessive nesting of loops,
conditionals, or functions can make the code difficult to
read and understand”.

A

Excessive Nesting

17
Q

“Overuse of primitive data types
can lead to code that is difficult to maintain and can
make it more difficult to add new features”.

A

Primitive Obsession

18
Q

Styles of Writing and General Tips
On comments:

A

Explain yourself in code.
* Good comment
* Legal comment
* Clarification comment
* Warning of consequence
* TODO comments

19
Q

Bad comments include:

A

mumbling, redundant,
misleading, mandated, journal comments, noise
comments, and scary noise.

20
Q

Styles of Writing and General Tips
On Functions:

A

Functions should only do one thing!
Flag arguments in functions are not a good idea!

21
Q

On Functions:
Arguments

zero arguments

22
Q

On Functions:
Arguments

one argument

23
Q

On Functions:
Arguments

two arguments

24
Q

On Functions:
Arguments

three arguments

25
On Functions: Arguments > 3 arguments
Polyadic
26
Principles and Rules
DRY Rule WET Rule KISS Rule Boy Scout Rule
27
Stands for “Don’t Repeat Yourself” Eliminate duplication of code
DRY Rule
28
Stands for “Write Everything Twice” Opposite of DRY Rule
WET Rule
29
Stands for “Keep it Simple, Stupid” Ensure the implementation of an algorithm or any piece of solution is done as simple as possible
KISS Rule
30
“Always leave the campground cleaner than you found it.”
Boy Scout Rule