I got probably "micro optimization" problem.
I got "History number", "Next Number", "Reset" buttons, as well "label" for text.
Every time I click At "Next number" button I would like to show random number in the label, and add this number to history array where I keep track of the past number.
Every time I click at "History number" it would randomly show one of the random numbers from history array.
Every time I click at "Reset" button, it would just clear history array.
And you can see that, that clicking at the "History number makes only sense when the history array is NOT empty.
And I wonder how to do this, without redundant "if" statement at the "history number" callback.
Deactivating "history number" button at the start of the program. Then activating it EVERY time the "next number" is clicked (which is uuugly). And deactivating this button again on "Reset" button.
This scheme on whiteboard demonstrate what I mean :
PS2: I though about having two "next number" functions.
1) One that would have the line of code that enable "history number" button and
2) second without.
At the start the 1) function would be handler. And at the end of that 1) function, the handler would replace itself to the 2) function.
Also the "reset" handler would put again handler to the 1) function.
PS3: I know, this could be overkill. But I just several times struggled with this kind of situation. And I wonder if there are better solution.
Thank you very very much in advance.