diff --git a/lectures/13_code_quality.md b/lectures/13_code_quality.md index e975bcc..b25e700 100644 --- a/lectures/13_code_quality.md +++ b/lectures/13_code_quality.md @@ -45,7 +45,6 @@ well-crafted :::::::::::: - # code smell > a code smell is a surface indication that usually corresponds to a deeper problem @@ -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 @@ -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} + ::: :::::: - ## code smells between classes Alternative Classes with Different Interfaces @@ -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 @@ -303,16 +308,17 @@ def calculate_circle_area(r: float) -> float: ::: -## structure over convention + -Encapsulate Boundary Conditions +## encapsulate boundary conditions ```python if level + 1 < length: @@ -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 diff --git a/lectures/figures/feature_envy.drawio.svg b/lectures/figures/feature_envy.drawio.svg new file mode 100644 index 0000000..490ca6e --- /dev/null +++ b/lectures/figures/feature_envy.drawio.svg @@ -0,0 +1,4 @@ + + + +
class B
+ do_something()
+ do_nothing()
class A
+ is_fall()
+ is_raining()
+ is_temperature_high()
+ is_pressure_low()
+ is_humidity_low()
\ No newline at end of file