Chapter XIX general control problem

Boolean expression

  • Use tureand falsedo Boolean judgment;
    • Implicitly compare Boolean values trueand false;
  • Simplify complex expressions;
    • Split complex determination and introducing new Boolean variables;
    • To make complex expressions Boolean function;
    • Instead of complex conditions with decision-making;
  • Write the positive character of the Boolean expression;
    • In the ifstatement, the determination condition converted from negative form is affirmative form, and exchange ifand elseclauses code;
    • With DeMorgan theorems simplified Boolean negative determination;
  • Boolean expressions with parentheses to make clearer;
    • In a simple counting techniques hereafter symmetric brackets;
  • Understanding how the Boolean expression evaluated;
  • Number in the order written numeric expression shaft;
  • 0 Compare with the guiding principles of;
    • Implicitly compare logic variables;
    • Comparing the number and 0;
    • In comparison explicitly C and the null terminator character ( `\ 0`);
    • The pointer and NULLcomparison phase;
  • Boolean expressions frequently asked questions;
  • In the C family of languages, should be placed on the left end of the constant comparison;
  • In C ++, the macro may be considered to replace the pre-created &&, ||, and ==;

Compound statements (statement block)

Compound statement refers to a set of statements, the group is considered a single statement statement to control program flow. Use guidelines in line with the statement:

  • To write together parentheses;
  • Use parentheses to articulate the condition.

Null statement

That is an empty statement containing only a semicolon statement.

  • Carefully use an empty statement;
  • Create an empty statement DoNothing()pretreatment macro or inline functions;
  • If consider switching to a non-null loop, it will make code clearer.

Tame dangerous deep nesting

Deeply nested software chief technology mission - management complexity - is contrary.

  • To simplify the nested condition by detecting a portion of the repeating of ifthe statement;
  • A breakblock to simplify nesting if;
  • The nested ifinto a set of if elsestatements;
  • The nest ifis converted into casestatements;
  • The deeply nested code extracted into separate program;
  • Use a more object-oriented approach;
  • Redesign deeply nested code.

Programming Fundamentals: Structured Programming

The core idea of ​​structured programming with a program should only use some SISO control structure.

Three components of structured programming

  • order;
  • select;
  • Iteration.

Control structure and complexity

Program complexity of a measure that, in order to understand the application, you must remember that the number of intelligence entity at the same time.

General principles of reduced complexity

To improve your own brain levels of the game by doing some mental connection; reduce your application's complexity.

  • How to measure the complexity of the
    • To measure the complexity of the decision point by the number of routine calculations;

Checklist: a control structure related issues

  • [] Expression is used trueand false, instead of 0 and 1?
  • [] Boolean value trueand falsecompare the implicit out well for you?
  • [] Value comparison is to show out well for you?
  • [] There by adding new Boolean variables, Boolean functions and decision tables to simplify the expression?
  • [] Boolean expression is an expression with a positive form of it?
  • [] Brackets paired it?
  • [] The need to use parentheses to clarify where you are using the brackets?
  • [] Judgment is in accordance with the order of the number of axes to write it?
  • [] If appropriate, Java is the judgment in the a.quals(b)way, and with no a==bway do?
  • [] Null statement expressed was obvious?
  • [] By re-judgment condition part is converted into if elseor casestatements, the nested subroutine code extraction into individual, switching to a more object-oriented design or other methods to simplify improved nested statements it?
  • [] If the decision point of a subroutine more than 10, then the justification can not redesign it?

Points

  • The simple Boolean expressions readable, will be very helpful to improve your quality of code;
  • Make deep nested subroutines become difficult to understand;
  • Structured programming is a simple idea and still applies: you can develop any program through the sequence, selection and combination of the three cycles;
  • The complexity is reduced to the lowest level so critical to write high-quality code.

Guess you like

Origin www.cnblogs.com/liam-ji/p/11548812.html