Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PyCon 2025 Darmstadt: Duplicate Code Dilemma - ...

PyCon 2025 Darmstadt: Duplicate Code Dilemma - Unlocking Automation with Open Source!

“Don’t Repeat Yourself” (DRY) is one of the first principles that every programmer encounters in the early stages of their coding journey. Some of us even had to learn it the hard way. We promised ourselves to avoid repetitive code to never again deal with the extensive refactoring required for every small change.

This simple principle has found a fundamental place in every programmer's heart. It may also be the reason why, from time to time, every programmer doubts their code and begins to refactor it in the early stages of coding.

This talk provides an overview of different solutions for preventing code repetition. We will start with the most common solutions, such as using git commands, and then explore more intermediate approaches for managing similarly structured repositories with the help of open-source template libraries such as Copier and Cookiecutter. Finally, we will address a more complex problem and examine how to automate updates using open-source tools like Renovate Bot.

As a takeaway, participants will gain insights into various solutions and a glimpse into the usability of each open-source library. Participants are also encouraged to reconsider the entire process: Are these solutions truly preventing repetitive code, or are we merely caught in an endless cycle of automation?

PyCon Link: https://pretalx.com/pyconde-pydata-2025/talk/KZKT9W/
Video: Will be uploaded after the talk

Avatar for raanasn

raanasn

April 05, 2025
Tweet

More Decks by raanasn

Other Decks in Programming

Transcript

  1. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Duplicate Code ‘Dilemma’ { < Raana Saheb-Nassagh > [Unlocking automation with open source] } slide_0
  2. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_1
  3. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_2 ‘catch_up’ { } 1999 „The evils of duplication“ – The pragmatic programmer 2008 „Duplication may be the root of all evil in software“ – Clean Code 2014 „Duplication is far cheaper than the wrong abstraction“ - Sandi Metz 2025 ?
  4. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_3 Data Scientist since 2020 Data Engineer @ dmTECH Boardgame lover ‘Raana Saheb-Nassagh’ { } Choir singer & piano player * source: artguru.ai profile.png *
  5. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_4 ‘An easy task’ { # old requirement repo 1 # old requirement repo 2 # old requirement repo 3 }
  6. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Some ideas? slide_5 # old requirement repo 1 # old requirement repo 2 # old requirement repo 3 The DIY enthusiast The tech geek The quick fixer The automation advocate
  7. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 The DIY enthusiast slide_6 regex - re - subprocess - tempfile - request - git-python
  8. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_7 ‘A little trickier task’ { # whole file needs a fix repo 1 # whole file needs a fix repo 2 # whole file needs a fix repo 3 }
  9. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_8 What else ..? The automation advocate The tech geek The DIY enthusiast The quick fixer
  10. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_9 The quick fixer #fixing whole file repo 1 pull main new branch change commit test/linter push review merge ci/cd pipeline - x NUMBER_OF_REPOS - ^ CHANGE_SIZE
  11. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_10 The clever quick fixer git magic - git fetch [remote-name] - git cherry-pick [sha1] - git format_patch - git am OR some open source? git-xargs multi-gitter
  12. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 The clever quick fixer git magic - git fetch [remote-name] - git cherry-pick [sha1] - git format_patch - git am OR some open source? git-xargs multi-gitter slide_11
  13. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_12 ‘A more interesting task’ { # fixing different lines in different files repo 1 repo 2 repo 3 }
  14. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_12 What else ..? The automation advocate The quick fixer The DIY enthusiast The tech geek
  15. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 The tech geek # code & structur repo 1 # same as above repo 2 # still same repo 3 THE TEMPLATE template repo Yeoman slide_13
  16. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 The tech aficionado # a lot similar code repo 1 # same as above repo 2 # still same repo 3 THE TEMPLATE template repo Yeoman 11
  17. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 The tech aficionado # a lot similar code repo 1 # same as above repo 2 # still same repo 3 THE TEMPLATE template repo Yeoman 11
  18. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_16 ‘So many duplicated commands?’ { repo 1 repo 2 repo 3 } copier update copier update copier update
  19. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_17 What else ..? The automation advocate The tech geek The quick fixer The DIY enthusiast
  20. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 The automation advocate slide_18 repo 1 repo 2 repo 3 THE TEMPLATE change Dependabot Celery Renovate Bot
  21. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 13
  22. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_20 The tech geek The automation advocate The DIY enthusiast So ..? The quick fixer
  23. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_20 The tech geek The automation advocate The DIY enthusiast What leads to duplicated code? The quick fixer
  24. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_20 The tech geek The automation advocate The DIY enthusiast What leads to duplicated code? The quick fixer
  25. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_20 The tech geek The automation advocate The DIY enthusiast What leads to duplicated code? The quick fixer
  26. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_20 The tech geek The automation advocate The DIY enthusiast What leads to duplicated code? The quick fixer
  27. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_20 The tech geek The automation advocate The DIY enthusiast What leads to duplicated code? The quick fixer
  28. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_20 The tech geek The automation advocate The DIY enthusiast What leads to duplicated code? The quick fixer
  29. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_20 The tech geek The automation advocate The DIY enthusiast What leads to duplicated code? The quick fixer Discuss the sources
  30. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_22 ‘may_I_suggest’ { } 1999 „The evils of duplication“ – The pragmatic programmer 2008 „Duplication may be the root of all evil in software“ – Clean Code 2014 „Duplication is far cheaper than the wrong abstraction“ - Sandi Metz 2025 „Address the (architectual) issues that lead to duplication, rather than just fixing the duplication itself."
  31. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_23 ‘thanks_to’ { } listening: ‘you’, supporting: ‘dmTECH’, reviewing: ‘my new & old peers’, stress_handling: ‘my partner’, contact slides
  32. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 slide_24 ‘sources’ { } - the pragmatic programmer - clean Code - sandi metz quote - multi-gitter - git-xargs - requests - git-python - copier - cookiecutter - yeoman - dependabot - celery - renovate bot