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.

  •  gender   ( @gender@beehaw.org ) 
    link
    fedilink
    English
    110 months ago

    In general there’s a balance to be struck between too few files and too many depending on the complexity of your code, but I can think of a few reasons you might want things to be split out for this project. One example would be to split initializing the mastodon client to its own file, then when you’re reading code that uses the client you don’t have to think about how the client was initialized.

    You’re right that it can be confusing when tightly coupled code is split between a bunch of files; to use your example it’d probably be cleaner to write petgrabber.ts as an independent function that returns a result, then have a ‘post to mastodon’ function that takes generic arguments, and call them both from the main file, taking the results from the petgrabber function, formatting them and passing them to your post to mastodon function.