Edit: my answer got some criticism in the comments, and I'm pretty sure the commentators are right and my answer is probably mostly nonsense.
Almost all of your answer is about performance, which we all agree is not an issue. The correct answer should address what is more clear, more readable, etc. – user949300
Your performance argument makes no sense, as you are compiling without optimizations. Skipping the else block is a trivial optimization for any compiler -- MartinHaTh
For the programmer reading it, I think it makes it quite clear. I am used to reading "if condition do stuff else do other stuff", so I can parse that pretty easily. The else block seems like a really logical spot for a comment explaining why we don't want to do anything in that condition.
But, will it make a significant impact if we have the empty block there? Is improved clarity for humans worth the cost? I think that's a language-specific (or rather, compiler/interpreter specific) question.
The only time I can think that this could have some negative impact is if it's in a bottleneck that needs to be ultra-optimized.
Even in those cases, it might make no difference. Here's an example of how I would check, for C.
sometimes it makes no difference to the compiled code
short.c
int main() {
if(1) {
printf("Hello World");
}
}
long.c
int main() {
if(1) {
printf("Hello World");
} else {
// not possible
}
}
Then I compiled both with the -S option to compile without assembling. I compared the assembly files and they were identical.
sometimes it does make a difference to the compiled code
I then updated the files and replaced if(1)
with int foo = 1; if(foo)
and repeated the process. (I know, the block is still not reachable - so if the compiler still treats it as unreachable I have proved nothing, but if the compiler treats it as reachable then I know I have successfully tricked the compiler and I have proven my point.) In this case, the compiled files were not identical - the compiler did not ignore the empty else block when it thought it was reachable.
short.s
## call to printf, etc. (i.e. the if block)...
LBB0_2:
## rest of code...
long.s
## call to printf, etc. (i.e. the if block)...
jmp LBB0_3 ## ! there is always a jump statement
LBB0_2:
jmp LBB0_3
LBB0_3:
## rest of code...
So in this almost reachable version, when the empty else block is included, there is an extra jump statement at the end of the if block. So if performance is a key concern here, then adding the empty else block is not a good idea.
conclusion
Based on the language, the else block could change the compiled code and affect performance. You would have to check for whichever language you're using, and then if it does have a performance hit in your language, decide if performance is more important than readability in this section of code.