Guidelines for a Language Independent Convention Identify global
Guidelines for a Language. Independent Convention • Identify global variables – Use g_prefix – Exp: g_Running. Total • Identify module variables – Use m_prefix – Exp: m_Compute • Identify type definitions – Use suffix _t – Exp: Color_t
Guidelines for a Language. Independent Convention • Identify named constants – Use suffix _c – Exp: Max. Recs_c • Identify enumerated types – Use suffix _e – Exp: Color_e • Format names to enhance readability – Exp: GYMNASTICPOINTTOTAL is less readable than Gymnastic. Point. Total
Guidelines for Language. Specific Conventions • C Conventions: – – – – c and ch are character variables i and j are integer indexes n is a number of something p is a pointer s is a string Preprocessor macros are typed in ALL_CAPS Variable and routine names are in lower _case The underscore (_) is used as a separator
General Abbreviations Guidelines • Use standard abbreviations (as in dictionary) • Remove all non-leading vowels (Computer becomes Cmptr, Screen becomes Scrn) • Use the first letter or first few letters of the word • Truncate after the first, second, or third letter • Keep the first and last letters • Use every significant word in the name • Remove useless suffixes – ing, ed, etc • Keep the most noticeable sound in each syllable
Comments on Abbreviations • Don’t abbreviate by removing one character from a word • Abbreviate consistently • Create names that you can pronounce • Avoid combinations that result in mispronunciation • Use a thesaurus to resolve naming collisions • Document short names with translation tables
General Issues in Using Variables • Scope – It refers to what extent your variables are known be can be referenced throughout a program – A variable can be visible in a function, a routine, or in the whole program – Some guidelines: • Minimize scope • Keep references to a variable together
General Issues in Using Variables • Persistence – It is the life span of a piece of data – Exp: new() in Pascal persists until dispose(), local persists in that particular function • Binding Time – Bind the variables at the latest – Exp: Use Test. ID = MAX instead of Test. ID = 100
General Issues in Using Variables • Using each variable for exactly one purpose – Use each variable for one purpose only – Avoid variables with hidden meanings • Exp: Page. Count is number of pages; but if the value is -1, it indicates an error msg – Make sure all declared variables are used
- Slides: 8