As I learn JS and design my self-study projects (SPAs mostly), I attempt to make sure I maintain separation of concerns and ensure each snippet of code that I write controls/does one thing.
Take the following example:
- I have a quiz application that presents questions, one at a time, to a user.
- The quiz has a 'Next' button, which calls a next() function.
- The next() function handles increasing the question index and retrieving the next question from the data source.
- Before I execute next(), I want to make sure the user gave a valid respnose - so I want to call a validate() function first; responsible for making sure the user input is valid.
In the above example, is it best practice to call validate() within my next() function, before it in sequence, or do I wrap both statements in a separate function and label it as a 'workflow'? This is greatly simplified, of course.
More broadly, is there a name for this topic? Perhaps something I can Google? 'Flow control' comes to mind, but when I Google that, the only thing that comes up are If statements, While loops, and basic control structures of the language itself. I'm looking for something more meta. Ironically, 'Design-patterns' seems to be too broad. Is there something in between?
Thank you in advance.
-Novice JS self-learner
Aucun commentaire:
Enregistrer un commentaire