vendredi 26 février 2021

In Lua, what is the best way to explicitly determine when something should be a module?

I'm have a lot of trouble getting started on a project because I cannot tell when I should make something a module or when it should be a variable, that is local to the instance I'm creating, with it's own set of related functions.

My gut instinct is to turn nearly everything in to a module, but I know this not only is unnecessary but actually harmful to creating clear, distinct code. I'll give an example but a small bit of information is that I'm using lua and a library to create a game.

So most "objects" in my game are going to have a name and a description, but I don't really feel that either of these are going to need modules as they will work just fine as variables accessed with setter/getter functions within the object if necessary. But my brain keeps questioning if maybe I should have a description module because then I could setup and expand descriptions more to exist as more than just simple strings. I don't have any current intentions to do so, but that's a lot of code to rewrite if I hard code descriptions for every variable in the game and then decide I want or NEED to expand the utility/functionality of descriptions.

This next part is not exactly related to this precise question and is a bit personal, feel free to skip this when answering.

I've been programming for nearly 20 years now, all sorts of different languages, all sorts of different programs and more and more I find myself questioning things like this. Seeing too much infinite possibility in the way to do things but never seeing the single best way that works for me and I get stuck in analysis paralysis and write little to no code, never getting past my psuedo-code planning phase.

Aucun commentaire:

Enregistrer un commentaire