I am currently working on a silly little project that will post pet’s up for adoption every hour to mastodon. I am struggling with how I should structure the project.

Should I put every single step in it’s own typescript module, like the main file calls the petgrabber function in petgrabber.ts after 1hr, than petgrabber calls the mastodon function in the mastodon.ts file, or should I just do a single file, or is there a way I am not thinking of. My biggest thing is them being interdependent on each other feels like it defeats the purpose of having them in their own file.

  • WontonSoup@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Compartmentalize things so they all handle one thing individually and then you call those things from a main class is generally the way you’d do it.

    Splitting things up will make your classes specific to a certain functionality and allow you to keep track of everything without individual files being thousands of lines, though sometimes they will end up that way anyway to achieve a single piece of functionality.

    So for example you might have a service to call the api to get data, a service that exclusively posts to mastodon, etc.

    You can write 500 lines of code to do something in your service and hide it away but then just call it like petInfoService.getPetInfo() from your main class and when you look at the flow it’ll make a lot more sense.

    Any reason you chose typescript out of curiosity? Nothing wrong with it, just curious.

    Feel free to post code if you need help. Just make sure whatever you’re posting or uploading to git doesn’t include any API keys.