Names and Naming Conventions


How do naming conventions help? Here are some ideas...


I suggest, because of the differences in assemblers you stick to a common case (for example lower case). Although this is not possible with PowerPC operating system calls, it tends to help avoid case problems. If necessary seperate the words with an underscore (_).

Generally names should tell the reader concisely what the routine/variable/etc does. By concisely I mean for example print_report, rather than prt_rpt (which could mean anything, and can be difficult to remember how the shortform is spelt).

A weak name is as bad as a terrible name. Names like do_calculation don't really tell you much....

Don't be afraid of long names - Fantasm in particular has good support for long names.



By using prefix's or postfix's you can identify what type of object this is.

For example:

g_global_variable_name - global variables prefixed with a g_

m_module_variable_name - module variables prefixed with a m_
(an alternative is _module_varable_name with an underscore rather than m_)

local_variable_name - a local variable name on the stack, or in a register.


_module_private_routine - private routines prefixed with an underscore

public_routine - routines avalible to be called by all modules

CONSTANTS - equated constants in all capitals.


Generally all names should try to relate to the problem domain (what you are actually doing rather than what the program is doing). So defining MAX_ARRAY_SIZE is poor, and MAX_EMPLOYEES is better. Defining FIVE as 5 is poor (what happens when you want to change it to six? Its worst than a number!) and MIN_PASSWORD_LENGTH would be better.

If you do need to use abbreviations try to keep it very understandable. Common abbreviations include MIN, MAX, POS, NUM (note use NO or NUM not both!).

Name a temporary varaible by the usage, when creating one - rather than a generic temporary name - especially the names of temporary variables on the stack (which don't take up any extra space). temp is always a difficult name to decode when reading a program, since the reader is not always sure what the temporary data is.


BACK TO ASSEMBLY CODING STYLES