Home CS439

CS439: C Style Guide

Programming is not a dry mechanical process, but a form of art. Well written code has an aesthetic appeal while poor form can make other programmers and instructors cringe. Programming assignments will be graded based on style and correctness. Good programming practices usually include many of the following principles:

General Programming Style

Specific Guidelines

Working in a Pre-Existing Infrastructure

When working in a pre-existing infrastructure, your goal is uniformity. If the existing code base is using 3 space indentation, then you do, too, regardless of your personal preferences. If the existing infrastructure begins all functions with the prefix "func", then you do, too. Uniformity is the best way to ensure the code is readable and maintainable.

Note that re-formatting the code base is not an acceptable method of ensuring that your code matches the pre-existing code.

Code Layout


Naming Conventions

Checking Return Values

System calls and library functions provide important information to the programmer via return values. You MUST check all return values and handle errors reasonably.

Initializing Pointers

When declaring a pointer, always initialize it. If you do not yet have a value for it, then initialize it to NULL. This rule is the number one way to avoid memory errors, which can be very difficult to find.