Boolean expression
- Use
ture
andfalse
do Boolean judgment;- Implicitly compare Boolean values
true
andfalse
;
- Implicitly compare Boolean values
- 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
if
statement, the determination condition converted from negative form is affirmative form, and exchangeif
andelse
clauses code; - With DeMorgan theorems simplified Boolean negative determination;
- In the
- 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
NULL
comparison 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
if
the statement; - A
break
block to simplify nestingif
; - The nested
if
into a set ofif else
statements; - The nest
if
is converted intocase
statements; - 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
true
andfalse
, instead of 0 and 1? - [] Boolean value
true
andfalse
compare 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 noa==b
way do? - [] Null statement expressed was obvious?
- [] By re-judgment condition part is converted into
if else
orcase
statements, 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.