Data Types

xiaoxiao2021-03-06  47

Numbers in general1. Avoid "Magic NumBers" .2. Use hard-code 0s and 1s if you need to. Anticipate Divide-by-Zero Errors.4. Make type conversions obvious.5. Avoid Mixed-Type Comparisons.

Integer1. Check for Integer Division.in The Real World 10 * (7/10) = (10 * 7) / 10 IS true, but not in the world of integer archmetic.2. Check for integer overflow.3. Check for overflow In Intermediate Results.Int A = 1000000INT B = 1000000INT C = a * B / 10000000IN Fact, C IS-727

FLOATING-POINT NUMBERS1. Avoid Additions and Subtractions on Numbers That Have Great DiffERENT MAGNITES2. Avoid Equality ComparisonS.3. Anticipate Rounding Errors.

Characters and Strings1. Avoid magic characters and string.2. Watch for off-by-one errors3. Know how your language and environment support Unicode.4. Decide on an internationalization / localization strategy early in the lifetime of a program.5. If You know you only need need to support a single alphabetic language, consider using an iso 8859 character set.6. Decide ON A Consistent Conversion Strategy Among String Types.

Boolean Variables1. Use Boolean Variables to Document Your Program.2. Use Boolean Variables To Simplify Complicated Tests.samples in P12

Enumerated Types for Readable.2. Use enumerated type for reliability.3. Use enumerated type for modifiability.4. Check for Invalid Values.

Named Constants IN Data Declarations.2. Avoid Litrals, Even "Safe" Ones.3. Use named constants consistently.

转载请注明原文地址:https://www.9cbs.com/read-110002.html

New Post(0)