this post was submitted on 20 Aug 2023
4 points (100.0% liked)
Transprogrammer
818 readers
1 users here now
A space for trans people who code
Matrix Space:
- #transprog:socki.moe
Rules:
- Don't be a meanie
- no *ism
- consider the feelings of somebody who might read what you say
- Don't shitpost
- Keep it wholesome
- Must be trans / programming related
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Agreeing with WontonSoup here:
OP, one common approach here is that code for calling to an external dependency should be split out into its own module that's called from some central place. That's a fairly natural way to organize code that tends to provide a good separation of concerns -- a lot of the times there's some sort of messy logic about calling an api or pulling something from the database, and its nice to have all that set aside from the core logic of what your app is actually doing.
As an app grows more complicated, you often end up wanting to add some additional layer. The result is a three-fold division at a high level: One "outer" layer dealing with the triggering context (e.g. an incoming http request), one core layer that handles any business/domain logic, and a third layer for handling all external dependencies. Then in each layer, you'd split things into specific files/modules based on grouped functionality.
There are a lot of specific ways of implementing this arrangement (and a lot of ways it can break down!), but the main point is to prevent certain types of complexity from creeping into places its not necessary. You want a structure that's easy to test, easy to reason about and navigate, and is easy to modify going forward.
In your case it sounds like you could start pretty simply:
Likely #2 could be folded into #1 for a simple project like you have in mind. It is still a good idea to at least separate it into its own method. :) You'll inevitably want to run it on demand (whether testing manually, or writing some sort of unit/integration test.)