You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> If you inherit from a class, but never use any of the inherited functionality, should you really be using inheritance? [@atwood2006code]
209
228
229
+
::: {.fragment .mt-4}
230
+
basically an architectural issue!
231
+
:::
232
+
210
233
:::::::::
211
234
::::::::: {.column width="30%"}
212
235
{width=250}
@@ -226,19 +249,21 @@ if not (
226
249
OOP principle: abstraction
227
250
~ - hiding the complex reality while exposing only the necessary parts
228
251
- 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
230
253
:::
231
254
232
255
233
256
## class-based smells: feature envy
234
257
235
258
{width=500}
236
259
260
+
::: {.wide-quote}
237
261
> Methods that make extensive use of another class may belong in another class.
238
262
> Consider moving this method to the class it is so envious of.
239
263
>
240
264
> -- Jeff Atwood [@atwood2006code]
241
265
266
+
:::
242
267
243
268
## more code smells
244
269
@@ -262,19 +287,23 @@ with own examples
262
287
263
288
version *n-1* (OOP)
264
289
290
+
::: {.text-larger}
265
291
```python
266
292
# increase class attribute
267
293
defincrease(self, by):
268
294
self.foo += by
269
295
```
296
+
:::
270
297
271
298
version *n* (FP)
272
299
300
+
::: {.text-larger}
273
301
```python
274
302
# increase class attribute
275
303
defincrease(what, by):
276
304
return what + by
277
305
```
306
+
:::
278
307
279
308
::: {.mt-2 .text-smaller}
280
309
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
285
314
286
315
**2. redundant comment**
287
316
317
+
::: {.text-larger}
288
318
```python
289
319
# creates an empty dataframe
290
320
defcreate_empty_dataframe(start_week, end_week):
291
321
```
322
+
:::
292
323
293
324
::: {.mt-5}
294
325
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
299
330
300
331
**3. commented-out code**
301
332
333
+
::: {.text-larger}
302
334
```python
303
335
defincrease(what, by):
304
336
# print(what, by)
305
337
return what + by
306
338
```
339
+
:::
307
340
308
341
not needed, just remove it
309
342
310
343
::: {.fragment}
344
+
::: {.text-larger}
311
345
```python
312
346
classSomething:
313
347
foo =0
@@ -321,6 +355,7 @@ class Something:
321
355
# def mutiply(self, by):
322
356
# self.foo *= by
323
357
```
358
+
:::
324
359
325
360
the version tracker will preserve it, if you might meed it sometime in the future
also increases consistency, the condition needs to be adjusted in one place
382
418
419
+
can be an adjustable parameter
420
+
383
421
384
422
# denoting blocks
385
423
@@ -465,7 +503,7 @@ fn main() {
465
503
466
504
## what could go wrong?
467
505
468
-
:::::: {.fragment}
506
+
:::::: {}
469
507
::: {.text-smaller}
470
508
parts from [sslKeyExchange.c](https://opensource.apple.com/source/Security/Security-55471/libsecurity_ssl/lib/sslKeyExchange.c?txt)
471
509
:::
@@ -491,7 +529,7 @@ fail:
491
529
return err;
492
530
```
493
531
494
-
::: {.fragment}
532
+
::: {}
495
533
more about Apple's "goto fail" fiasco (2014): [@wheeler2014apple], [@migues2014understanding]
496
534
497
535
false blame on `goto`, could be prevented by review and testing
@@ -813,15 +851,6 @@ Licence: 0.00-->
813
851
814
852
# code chunk permanence in a codebase
815
853
816
-
<!--:::::::::::: {.columns}
817
-
::::::::: {.column width="50%"}
818
-
819
-
:::::::::
820
-
::::::::: {.column width="50%"}
821
-
822
-
:::::::::
823
-
::::::::::::-->
824
-
825
854
 (Git history analyser) documentation](https://raw.githubusercontent.com/src-d/hercules/refs/heads/master/doc/linux.png){width=400}
0 commit comments