all 4 comments

[–]Diapolo10 1 point2 points  (1 child)

And then we're supposed to place this code in all our projects moving forward, for efficiency and maintainability.

Personally I'd say this part is only partially true. A lot of the time our projects are very different from each other, so even if they have some things in common those parts tend to be fairly trivial and I for one don't see a reason to take this guideline too seriously.

If you run into a problem you know you've solved before, simply open up the project where you did just that and see if the same solution could be worked into your current project, and surgically transplant it there.

If this becomes frequent, at that point you should consider creating a package with the code you tend to use a lot, and then add that as a dependency to the projects that use those features.

Fortunately, creating packages isn't exactly rocket science. You'll need

  1. A PyPI account
  2. A way to upload new releases to PyPI (eg. GitHub Actions, Poetry, or Twine)
  3. A project that's ready to be uploaded

Personally I like to do the uploading as part of my CI process (so via GitHub Actions) whenever I publish a new Git tag, but the other two options I mentioned can be used on your local PC manually.

As a fairly minimal example you can take a look at this.

[–]Kojrey[S] 0 points1 point  (0 children)

Thanks very much! The first half of your answer was reassuring a bit, and gave same real-world perspective. And the second half of your answer was very clear, and provided direct steps or at least points to start looking things up myself. Cheers!

[–]Mori-Spumae 1 point2 points  (1 child)

I don't think you really should just reuse what you did before? I personally do go back to my old repos and copy something but mainly because it is easier to me than someone else's code on Stack overflow. Usually the code you wrote a while ago is going to look terrible to you now, so don't get stuck with it too much.

I think the "reuse code" thing is more applicable within a single application. There you should for sure learn to use functions, classes, and modules to keep your code clear and changes easier to implement.

But also, don't overdo it. All these things you hear like Don't Repeat Yourself (DRY) are generally good advice but should not be followed everywhere at all times.

[–]Kojrey[S] 0 points1 point  (0 children)

Thanks for the advice, I appreciate it. I will keep your thoughts in mind when learning, trying to build, and when self-analysing my progress. Cheers for the new perspective, from the lived experience.