terralib:convencaoprograma
Diferenças
Aqui você vê as diferenças entre duas revisões dessa página.
| Ambos lados da revisão anteriorRevisão anteriorPróxima revisão | Revisão anterior | ||
| terralib:convencaoprograma [2008/04/02 12:50] – laercio | terralib:convencaoprograma [2008/04/02 19:22] (atual) – laercio | ||
|---|---|---|---|
| Linha 17: | Linha 17: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| ====== Preprocessador ====== | ====== Preprocessador ====== | ||
| * Use '# | * Use '# | ||
| - | * Place preprocessor include guard in header files | + | * Place preprocessor include guard (macros associadas a arquivos include) |
| * Use #if. . #endif and #if def . . #endif instead of "/* . . .*/" comments to hide blocks of code | * Use #if. . #endif and #if def . . #endif instead of "/* . . .*/" comments to hide blocks of code | ||
| * Use macros sparingly | * Use macros sparingly | ||
| * Do not use "# | * Do not use "# | ||
| + | |||
| + | ===== Example ===== | ||
| + | <code cpp> | ||
| + | #ifndef TE_CONNECTION_POOL_H | ||
| + | #define TE_CONNECTION_POOL_H | ||
| + | .... | ||
| + | static const float TeMaxFloat = 3.4e37; | ||
| + | .... | ||
| + | #endif // end TE_CONNECTION_POOL_H | ||
| + | </ | ||
| + | |||
| Linha 30: | Linha 42: | ||
| * Do not define enumerations using macros or integer constants | * Do not define enumerations using macros or integer constants | ||
| * Declare enumerations within a namespace or class | * Declare enumerations within a namespace or class | ||
| + | |||
| + | ===== Example ===== | ||
| + | <code cpp> | ||
| + | typedef std:: | ||
| + | typedef std:: | ||
| + | |||
| + | enum TeSelectionMode | ||
| + | { | ||
| + | TeSelectionModeDefault, | ||
| + | TeSelectionModeTePointed, | ||
| + | TeSelectionModeTeQueried, | ||
| + | TeSelectionModeTePointedQueried //!< object pointed and queried | ||
| + | } | ||
| + | </ | ||
| + | |||
| ====== Escopo ====== | ====== Escopo ====== | ||
| * Declare for-loop iteration variables inside of for statements | * Declare for-loop iteration variables inside of for statements | ||
| + | ===== Example ===== | ||
| + | <code cpp> | ||
| + | for (int i = 0; i < 10; i++) | ||
| + | </ | ||
| Linha 100: | Linha 130: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| Linha 106: | Linha 137: | ||
| * Use C++ casting operators instead of C-style casts. Ex:<code cpp> | * Use C++ casting operators instead of C-style casts. Ex:<code cpp> | ||
| - | short a=2000; | + | short a = 2000; |
| int b; | int b; | ||
| b = (int) a; // c-like cast notation - Ok only for fundamental data types | b = (int) a; // c-like cast notation - Ok only for fundamental data types | ||
| - | double d=3.14159265; | + | double d = 3.14159265; |
| int i = static_cast< | int i = static_cast< | ||
| </ | </ | ||
| Linha 127: | Linha 158: | ||
| </ | </ | ||
| * Test all type conversions | * Test all type conversions | ||
| + | |||
| Linha 141: | Linha 173: | ||
| * Declare and initialize static variables within functions | * Declare and initialize static variables within functions | ||
| * Zero pointers after deletion | * Zero pointers after deletion | ||
| - | * Use the new and delete operators instead of malloc() and free() | + | * Use the **new** and **delete** operators instead of **malloc()** and **free()** |
| Linha 150: | Linha 183: | ||
| * Do not test for equality with true | * Do not test for equality with true | ||
| * Replace repeated non-trivial expressions with equivalent methods | * Replace repeated non-trivial expressions with equivalent methods | ||
| - | * Use size-t variables for simple loop iteration and array subscripts | + | * Use **size-t** variables for simple loop iteration and array subscripts |
| * Use a dummy template function to eliminate warnings for unused variables | * Use a dummy template function to eliminate warnings for unused variables | ||
| + | |||
| ====== Fluxo de Controle ====== | ====== Fluxo de Controle ====== | ||
| - | * Avoid break and continue in iteration statements | + | * Avoid **break** and **continue** in iteration statements |
| - | * Avoid multiple return statements in functions | + | * Avoid multiple |
| - | * Do not use goto | + | * Do not use **goto** |
| - | * Do not use try . .throw. .catch to manage control flow | + | * Do not use **try .. throw .. catch** to manage control flow |
| - | * Never use setjmp() or longjmp() in a C++ program | + | * Never use **setjmp()** or **longjmp()** in a C++ program |
| - | * Always code a break statement in the last case of a switch statement | + | * Always code a **break** statement in the last case of a switch statement |
| Linha 172: | Linha 207: | ||
| * Manage resources with RAII for exception safety | * Manage resources with RAII for exception safety | ||
| * Catch exceptions by reference, not by value | * Catch exceptions by reference, not by value | ||
| - | * Do not discard exception information if you throw a new exception within a catch block | + | * Do not discard exception information if you throw a new exception within a **catch** block |
| * Avoid throwing exceptions in destructors | * Avoid throwing exceptions in destructors | ||
terralib/convencaoprograma.1207140652.txt.gz · Última modificação: 2008/04/02 12:50 por laercio
