The question is not specific enough, “full of if-else branches”, does it mean that there are many branches at the same level in the same function? Or is there a lot of branches in the same file or module? Or is the nesting level of branches very deep? Say there are many branches, how many are there? tens of? If there are many branches of the same function at the same level, it means that there are too many variables used to judge the condition in the logic expression. Otherwise, if there are many values of a variable, as long as it is enumerable, switch-case should be given priority. When the variable of the judgment condition is one, there are two choices; when there are two variables, there are four combinations, up to four branches; and so on, as the number of variables increases, the number of branches increases exponentially. Anyone who has studied algorithm complexity analysis knows that any exponential consumption, regardless of time or space, is a disaster for the current Turing computer. However, the exponential growth of the if-else branch will not have much impact on the operating efficiency of the program, and it is estimated that the variables of the judgment condition will not exceed five. The operating efficiency of the program is often more related to the number of loops, the number of loop nesting, the depth of the call stack, and the blockage of read and write. One more branch statement is just to do a few more logical expression operations and program pointer jumps, not to mention the short-circuit optimization of logical expressions, which will not cause a bottleneck in operating efficiency. The exponential growth of the if-else branch is more a test of human logic. People like to pursue great unification, and hope that the four forces can best share a theoretical model, because this is in line with people’s nature to pursue simplicity in cognition. When you say “except for maintainability”, you seem to have a dismissive tone. It seems that only the efficiency of the program is important. This is a bad attitude that many junior programmers tend to hold. To say that poor maintainability is just the appearance, and the inner description is the design of the program when coding: the model is not concise enough, the boundary is sloppy, and the test is not complete. These reflect that the coders are not thinking deeply and adequately. For a function, the more branches inside, the more abnormal situations. The more abnormal situations, it means that the designed model is not universal enough, and it needs to be patched through logic branches. If you try to write test cases, you will find that if you want to cover each line of code, there are several branches, and you have to design several test cases. Ideally, if there is no branch, then only one test case is needed, but in reality, this is impossible, and there will always be various abnormal situations. For example, anyone who has brushed LeetCode knows that the realization of a string-to-integer function (atoi) is a simple-sounding problem, but the pass rate is not high. The fundamental reason is that most people cannot fully understand The possible exceptions in the string are very clear. Many abnormal situations are the main reason for the many branches, but in the case of in-depth thinking, the number of branches can still be controlled to the right number, and the top-down decomposition problem is the main method to solve the confusion of branches. People who have studied calculus probably like elementary functions that can be derived everywhere, but they don’t have a good impression of piecewise functions. In order to solve the problem that programmers do not think deeply, test-driven development is advocated in the industry. When a person starts to look at the function written by himself from the perspective of a user, if he wants to achieve high code coverage, he will definitely be assisted. Deepen your thinking.