Skip to content

Commit

Permalink
Add feature envy slide #29
Browse files Browse the repository at this point in the history
  • Loading branch information
pintergreg committed Oct 29, 2024
1 parent 0b29051 commit cbc108f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
34 changes: 21 additions & 13 deletions lectures/13_code_quality.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ well-crafted
::::::::::::



# code smell

> a code smell is a surface indication that usually corresponds to a deeper problem
Expand All @@ -63,6 +62,7 @@ software rot is the degradation, deterioration, or loss of the use or performanc
:::::::::
::::::::::::


## clean clode violations as code smells

- long method
Expand Down Expand Up @@ -165,13 +165,12 @@ if not (
::: {.text-smaller}
- hard to understand, even if it is tested and documented
- use nested conditions instead
- avoid negative conditionals -- Robert C. Martin [@martin2009clean]
- `if (!is_raining()) {do_something();}`{.javascript}
<!--- avoid negative conditionals -- Robert C. Martin [@martin2009clean]
- `if (!is_raining()) {do_something();}`{.javascript}-->
:::
::::::



## code smells between classes

Alternative Classes with Different Interfaces
Expand All @@ -182,10 +181,16 @@ Data Clumps

Refused Bequest

Indecent Exposure
## class-based smells: indecent exposure

Feature Envy
## class-based smells: feature envy

![](figures/feature_envy.drawio.svg){width=500}

> Methods that make extensive use of another class may belong in another class.
> Consider moving this method to the class it is so envious of.
>
> -- Jeff Atwood [@atwood2006code]

## more code smells
Expand Down Expand Up @@ -303,16 +308,17 @@ def calculate_circle_area(r: float) -> float:
:::


## structure over convention
<!--## structure over convention
Enforce design decisions with structure over convention. Naming conventions are good,
but they are inferior to structures that force compliance. For example, switch/cases with
nicely named enumerations are inferior to base classes with abstract methods. No one is
forced to implement the switch/case statement the same way each time; but the base
classes do enforce that concrete classes have all abstract methods implemented.
> Enforce design decisions with structure over convention.
> Naming conventions are good, but they are inferior to structures that force compliance.
> For example, switch/cases with nicely named enumerations are inferior to base classes with abstract methods.
> No one is forced to implement the switch/case statement the same way each time; but the base classes do enforce that concrete classes have all abstract methods implemented.
>
> -- Robert C. Martin [@martin2009clean]-->


Encapsulate Boundary Conditions
## encapsulate boundary conditions

```python
if level + 1 < length:
Expand All @@ -325,6 +331,8 @@ if next_level < length:
do_somthing(foo, bar, next_level)
```

also increases consistency, the condition needs to be adjusted in one place


# denoting blocks

Expand Down
4 changes: 4 additions & 0 deletions lectures/figures/feature_envy.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cbc108f

Please sign in to comment.