Presentation is loading. Please wait.

Presentation is loading. Please wait.

Guidelines for a Language- Independent Convention Identify global variables –Use g_prefix –Exp: g_RunningTotal Identify module variables –Use m_prefix.

Similar presentations


Presentation on theme: "Guidelines for a Language- Independent Convention Identify global variables –Use g_prefix –Exp: g_RunningTotal Identify module variables –Use m_prefix."— Presentation transcript:

1 Guidelines for a Language- Independent Convention Identify global variables –Use g_prefix –Exp: g_RunningTotal Identify module variables –Use m_prefix –Exp: m_Compute Identify type definitions –Use suffix _t –Exp: Color_t

2 Guidelines for a Language- Independent Convention Identify named constants –Use suffix _c –Exp: MaxRecs_c Identify enumerated types –Use suffix _e –Exp: Color_e Format names to enhance readability –Exp: GYMNASTICPOINTTOTAL is less readable than GymnasticPointTotal

3 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

4 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

5 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 mis- pronunciation Use a thesaurus to resolve naming collisions Document short names with translation tables

6 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

7 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 TestID = MAX instead of TestID = 100

8 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: PageCount is number of pages; but if the value is -1, it indicates an error msg –Make sure all declared variables are used


Download ppt "Guidelines for a Language- Independent Convention Identify global variables –Use g_prefix –Exp: g_RunningTotal Identify module variables –Use m_prefix."

Similar presentations


Ads by Google