COMP 3430 – Operating Systems
Programming Standards
Franklin Bristow
2022
This document lists the programming standards that you must follow for the
programming questions of your assignments and exams.
Failure to follow these standards will result in the loss of marks.
1. Each of your program files must begin with a comment block like the
following:
2. If the purpose of a routine is not self-explanatory, write a prologue comment
at the beginning, similar to the following:
//-----------------------------------------
// NAME: your name
// STUDENT NUMBER: your student number
// COURSE: COMP 3430, SECTION: Axx
// INSTRUCTOR: name of your instructor
// ASSIGNMENT: assignment #, QUESTION: question #
//
// REMARKS: What is the purpose of this program?
//
//-----------------------------------------
//------------------------------------------------------
// myRoutine
//
// PURPOSE: tell me what it does!
// INPUT PARAMETERS:
// Describe those parameters which accept data values.
// OUTPUT PARAMETERS:
// Describe those parameters which return values.
// Include the value returned by the routine if not void.
// Some of these may be the same as the input
COMP 3430 – Operating Systems
2/3
Parts of the prologue may be omitted if appropriate, e.g., if the
routine
has no parameters.
3. Use blank lines to separate blocks of code and declarations to improve
readability. In particular, use blank lines between declarations and other
code, and between routines.
4. Comment blocks of code. Describe why you wrote the code this way, not what
each line does. For example:
5. Use meaningful but reasonable variable names.
a – Very bad. too short, not meaningful.
averageMark – Good
average_of_all_the_marks_in_the_list – Bad. Too long and wordy.
If a concise variable name does not completely describe the data it stores, add
a comment to the declaration with additional information.
6. Use indentation properly, and align else with the corresponding if for
readability. Any readable and consistent style is acceptable. The essential
features are that all statements that are nested within another statement
must be indented, and that the braces { } must be in predictable and
consistent positions. Common styles include:
// parameters.
//------------------------------------------------------
... myRoutine(...)
// Print the results.
printf("The taxes payable are:\n");
printf("Federal tax = %d\n", federalTax);
if-while-else-etc {
stuff-inside
stuff-inside
}
if-while-else-etc
{
stuff-inside
stuff-inside
}
if-while-else-etc
{
stuff-inside
COMP 3430 – Operating Systems
3/3
7. Declare all variables at the beginning of a routine and never within a sub-
block.
8. Avoid the use of literal constants (“magic numbers”) in your program.
Generally use constant identifiers rather than literal constants in your
program. Acceptable exceptions are strings that appear only once in output
titles and headings, and small fundamental values. Examples,
sum = 0; literal constant 0 is OK
count = count + 1; literal constant 1 is OK
price = total * 1.07; not proper. Create a named constant like
PST_RATE = 1.07.
lastDigit = accountNumber % 10; literal constant 10 is OK in this
context (i.e., mod 10 to get the last digit is a well-known practice).
if(codeLetter == 'R') not proper. Create a named constant like
REFUND_CODE = 'R'.
9. Appropriate prompts should always be used for interactive input.
10. All output produced by your programs must have appropriate titles and
headings.
11. The output of a program should contain a message to the effect that the
program completed its task normally, e.g. “end of processing”, “program
completed normally”, “all done”, or an equivalent. For example:
12. Never change the value of a for loop variable inside the loop.
13. Avoid the duplication of code. Every job, task, or formula should be
implemented in one place.
stuff-inside
}
printf("Program completed normally.");
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。