Tech Tip: Adding type suffix to variables as a memory aid
PRODUCT: 4D | VERSION: 13.2 | PLATFORM: Mac & Win
Published On: April 19, 2013
When working with a large method with lots of variables of many types it can become difficult to remember what type a variable is. A helpful coding practice is to add a variable type prefix of suffix to all variables. The next time the a variable of a certain type is needed it is then easy to verify a variable of the correct type is being used.
Below are two examples of how to declare variables suffixed and prefixed with their types. Each developer will prefer their own style but regardless of prefix or suffix the aid of knowing the variable type is the same.
Local variables Suffixed with type
C_BOOLEAN($MyVar_B) C_BLOB($MyVar_X) C_DATE($MyVar_D) C_GRAPH($MyVar_C) // C for Chart C_INTEGER($MyVar_I) C_LONGINT($MyVar_L) C_PICTURE($MyVar_G) // G for Graphic C_POINTER($MyVar_P) C_REAL($MyVar_R) C_STRING(255;$MyVar_Snnn) // nnn replaced with string size C_TEXT($MyVar_T) C_TIME($MyVar_H) // H for hour |
Local variables Prefixed with type
C_BOOLEAN($B_MyVar) C_BLOB($X_MyVar) C_DATE($D_MyVar) C_GRAPH($C_MyVar) // C for Chart C_INTEGER($I_MyVar) C_LONGINT($L_MyVar) C_PICTURE($G_MyVar) // G for Graphic C_POINTER($P_MyVar) C_REAL($R_MyVar) C_STRING(255;$Snnn_MyVar) // nnn replaced with string size C_TEXT($T_MyVar) C_TIME($H_MyVar) // H for hour |
Commented by Justin Leavens on April 26, 2013 at 12:43 PM
But only one method is correct :-)