First, let me set up some context.
I have a function that simulates a user typing a string, printing each character of the buffer at a fixed delay.
But now, I want another behaviour. There has to be a random delay if the user wants, so it will now print each character at a random delay between two numbers.
- If you add this behaviour to a separate function, it would be almost the same, a copy-paste, except that for now, it takes a tuple (float, float) that specifies the upper bound and lower bound of the random number to be generated.
- But if you had this functionality on the same function that takes a fixed delay, you would need to add extra parameters, such as random_delay to be true or false, and then another param to receive the tuple for the boundaries.
- You can also make the delay parameter, to take a tuple or float, type check it, and take the path accordingly to the type. The function also has the new parameter random_delay that takes true or false. But this strategy and 2 leads to the question. Doesn't a new behaviour lead inherently to belong to a new function?
I am a student going through a more analytical approach building stuff and will be great to hear your opinion about it, even for such a simple problem. Would you use option 1, 2 or 3, or even take another approach? Thanks for your insight.