Skip to content

Commit dd27509

Browse files
committed
Adjust presentation formatting GH-47
1 parent 08c603b commit dd27509

1 file changed

Lines changed: 54 additions & 25 deletions

File tree

lectures/13_code_quality.md

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ software craftmanship
2727

2828
:::
2929

30-
:::::::::::: {.columns .mt-2 .fragment height=240}
31-
::::::::: {.column width="70%" .text-align-left}
32-
::: {.text-align-left}
30+
::: {.text-align-left .mt-2}
3331
well-crafted
3432
~ - high quality
3533
- well-designed
@@ -38,23 +36,20 @@ well-crafted
3836
- code is clean, easy to understand, **maintain**
3937

4038
:::
41-
:::::::::
42-
::::::::: {.column width="30%"}
43-
44-
:::::::::
45-
::::::::::::
46-
4739

4840
# code smell
4941

42+
::: {.wide-quote}
5043
> a code smell is a surface indication that usually corresponds to a deeper problem
5144
>
5245
> -- Martin Flower [@fowler2006code]
5346
47+
:::
5448

5549
:::::::::::: {.columns .mt-3}
5650
::::::::: {.column width="40%" .text-smaller}
5751
software rot is the degradation, deterioration, or loss of the use or performance of software over time [@enwiki:1236668404]
52+
5853
:::::::::
5954
::::::::: {.column width="40%" .text-smaller}
6055
**requirement smell**: signs in the requirements that are not necessarily wrong but could be problematic [@femmer2017rapid]
@@ -165,11 +160,31 @@ if not (
165160
::: {.text-smaller}
166161
- hard to understand, even if it is tested and documented
167162
- use nested conditions instead
168-
<!--- avoid negative conditionals -- Robert C. Martin [@martin2009clean]
169-
- `if (!is_raining()) {do_something();}`{.javascript}-->
163+
- avoid negative conditionals -- Robert C. Martin [@martin2009clean]
164+
- `if (!is_raining()) {do_something();}`{.javascript}
170165
:::
171166
::::::
172167

168+
## conditional complexity -- use nested conditions {visibility=hidden}
169+
170+
```python
171+
if not (
172+
is_pressure_low()
173+
or (is_temperature_high() and not is_humidity_low())
174+
and (is_fall() or not is_raining())
175+
):
176+
do_something()
177+
```
178+
179+
```python
180+
if not (
181+
is_pressure_low()
182+
or (is_temperature_high() and not is_humidity_low())
183+
and (is_fall() or not is_raining())
184+
):
185+
do_something()
186+
```
187+
173188

174189
## class-based smells: alternative classes with different interfaces {visibility=hidden}
175190

@@ -179,8 +194,12 @@ if not (
179194
## class-based smells: data class???
180195

181196
:::::::::::: {.columns}
182-
::::::::: {.column width="70%"}
183-
> Avoid classes that passively store data. Classes should contain data and methods to operate on that data, too [@atwood2006code].
197+
::::::::: {.column width="70%" .wide-quote}
198+
> Avoid classes that passively store data. Classes should contain data and methods to operate on that data, too.
199+
>
200+
> -- Jeff Atwood [@atwood2006code]
201+
202+
comes from the OOP definition, but outdated
184203

185204
::: {.mt-3}
186205
- Kotlin: [Data classes](https://kotlinlang.org/docs/data-classes.html)
@@ -207,6 +226,10 @@ if not (
207226
::::::::: {.column width="70%" .mt-5}
208227
> If you inherit from a class, but never use any of the inherited functionality, should you really be using inheritance? [@atwood2006code]
209228
229+
::: {.fragment .mt-4}
230+
basically an architectural issue!
231+
:::
232+
210233
:::::::::
211234
::::::::: {.column width="30%"}
212235
![](figures/no_middleman.drawio.svg){width=250}
@@ -226,19 +249,21 @@ if not (
226249
OOP principle: abstraction
227250
~ - hiding the complex reality while exposing only the necessary parts
228251
- allows to focus on interactions at a higher level without needing to understand the details of the implementation
229-
- achieved through abstract classes and interfaces, which define a contract for what methods an object must implement without specifying how they should be implemented
252+
- can be achieved through abstract classes and interfaces, which define a contract for what methods an object must implement without specifying how they should be implemented
230253
:::
231254

232255

233256
## class-based smells: feature envy
234257

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

260+
::: {.wide-quote}
237261
> Methods that make extensive use of another class may belong in another class.
238262
> Consider moving this method to the class it is so envious of.
239263
>
240264
> -- Jeff Atwood [@atwood2006code]
241265
266+
:::
242267

243268
## more code smells
244269

@@ -262,19 +287,23 @@ with own examples
262287

263288
version *n-1* (OOP)
264289

290+
::: {.text-larger}
265291
```python
266292
# increase class attribute
267293
def increase(self, by):
268294
self.foo += by
269295
```
296+
:::
270297

271298
version *n* (FP)
272299

300+
::: {.text-larger}
273301
```python
274302
# increase class attribute
275303
def increase(what, by):
276304
return what + by
277305
```
306+
:::
278307

279308
::: {.mt-2 .text-smaller}
280309
these are actually noise comments, so they are bad in the first place
@@ -285,10 +314,12 @@ these are actually noise comments, so they are bad in the first place
285314

286315
**2. redundant comment**
287316

317+
::: {.text-larger}
288318
```python
289319
# creates an empty dataframe
290320
def create_empty_dataframe(start_week, end_week):
291321
```
322+
:::
292323

293324
::: {.mt-5}
294325
redundant as it does not give new information, a form of noise comment
@@ -299,15 +330,18 @@ redundant as it does not give new information, a form of noise comment
299330

300331
**3. commented-out code**
301332

333+
::: {.text-larger}
302334
```python
303335
def increase(what, by):
304336
# print(what, by)
305337
return what + by
306338
```
339+
:::
307340

308341
not needed, just remove it
309342

310343
::: {.fragment}
344+
::: {.text-larger}
311345
```python
312346
class Something:
313347
foo = 0
@@ -321,6 +355,7 @@ class Something:
321355
# def mutiply(self, by):
322356
# self.foo *= by
323357
```
358+
:::
324359

325360
the version tracker will preserve it, if you might meed it sometime in the future
326361
:::
@@ -339,6 +374,7 @@ def calculate_circle_area(r: float) -> float:
339374
```python
340375
PI = 3.141592
341376

377+
342378
def calculate_circle_area(r: float) -> float:
343379
return r * r * PI
344380
```
@@ -380,6 +416,8 @@ if next_level < length:
380416

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

419+
can be an adjustable parameter
420+
383421

384422
# denoting blocks
385423

@@ -465,7 +503,7 @@ fn main() {
465503

466504
## what could go wrong?
467505

468-
:::::: {.fragment}
506+
:::::: {}
469507
::: {.text-smaller}
470508
parts from [sslKeyExchange.c](https://opensource.apple.com/source/Security/Security-55471/libsecurity_ssl/lib/sslKeyExchange.c?txt)
471509
:::
@@ -491,7 +529,7 @@ fail:
491529
return err;
492530
```
493531
494-
::: {.fragment}
532+
::: {}
495533
more about Apple's "goto fail" fiasco (2014): [@wheeler2014apple], [@migues2014understanding]
496534
497535
false blame on `goto`, could be prevented by review and testing
@@ -813,15 +851,6 @@ Licence: 0.00-->
813851

814852
# code chunk permanence in a codebase
815853

816-
<!--:::::::::::: {.columns}
817-
::::::::: {.column width="50%"}
818-
819-
:::::::::
820-
::::::::: {.column width="50%"}
821-
822-
:::::::::
823-
::::::::::::-->
824-
825854
![Linux codebase -- from the [Hercules](https://github.com/src-d/hercules) (Git history analyser) documentation](https://raw.githubusercontent.com/src-d/hercules/refs/heads/master/doc/linux.png){width=400}
826855

827856
::: {.mt-2}

0 commit comments

Comments
 (0)