if( test1 && test2 && test3){ Done(); } if(!test1) return; if(!test2) return; if(!test3) return; Done(); if(test1){ if(test2){ if(test3){ Done(); } } } if( test1 && test2 && test3){ Done(); } if(!test1) return; if(!test2) return; if(!test3) return; Done(); if(test1){ if(test2){ if(test3){ Done(); } } } The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .
You should not think about nano-optimizations like swapping rows. Think about the meaning of the code. The meaning in all three cases is the same, so there is essentially no difference.
What should worry you is how it is easier for you to read and understand the code. But which of the three options is more readable, you decide. I personally do not like the third option in excessive nesting, but in your code you choose.
In the current version, the assembler code generated for these three functions is slightly different . But this is only a temporary imperfection of the JIT compiler; for example, the C ++ Clang compiler with enabled maximum optimizations compiles all three pieces into the same object code .
From the point of view of execution speed, it will be the same, in any case, the compiler optimizes all this, and the output after compiling the code will not be the same as you wrote in the C # code.
But from the point of view of the beauty of the code, the best option is the 1st one as the most clear and transparent.
The beauty of the code is a very important parameter, since in a real project, refactoring and parsing code can be up to 80% of the total programming time, so clear and understandable code is very important.
if( test1 && test2 && test3){ Done(); } In terms of speed of work, all the options, it seems to me, are about the same.
From the point of view of the number of generated code by the compiler, options 1 and 3 are approximately the same, in option 2 there will be a little more code.
In terms of code readability, I would prefer option 1
Source: https://ru.stackoverflow.com/questions/771022/
All Articles