In your opinion, do you think it is a waste of time to make checks that you know there is no possible way of it being there/not being there, or would you just put it there just in case there is a bug or something?  For example, below checks to see if a button is visible, then music is playing, but there is no way for that button to be shown without the music playing:if (buttonVisible)    if ([music playing] == true) //is always true if the button is visible        [music stopPlaying];
Would it be better to have extra checks, or would it be a waste of time?
programming languages;object oriented;programming practices;performance
What if:Some other application manipulates the window and renders the button visible while the music is not playing?A thread stops the music and is about to hide the button when you check the visibility of a button?Some other developer modifies the code, without knowing the relationship between the visibility of the button and the music state?You modify the code since the requirements changed and instead of hiding the button, you were required to only disable it?You replace the button by some other control?In other words:You shouldn't check for a condition if there is no possible way of it being true/false. For example the if block in the following code is redundant and should be removed:assert(input > 0);var i = input * 2;if (i > 0){    // Do something useful.}You should check for a condition in a case like the one you illustrated, since there is no strict and reliable relation between the visibility of a button and the state of the music.Note that in your code, what you should omit is the first if. Since you simply want to stop the music (and for a reason, you can't just call music stopPlaying if the music is not playing), the only check you should do is if ([music playing]). That the button is visible or not doesn't matter. You don't care whether it is visible or not, enabled or not, or even if it exists.For example something like:if ([button visible])    if ([music playing])        [music stopPlaying]        [button hide]could be rewritten as:if ([music playing])    [music stopPlaying]    [button hide]if the visibility of the button relies on the state of the music. Data binding, if supported by your language/framework, is even better:[button visibility=(bind:music state)]// Later in code:if ([music playing])    [music stopPlaying] // The button is hidden automatically