guidelines for a language- independent convention identify global variables –use g_prefix –exp:...

8
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

Upload: rosanna-wade

Post on 05-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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