YaST2 Developer Pages: Coding Rules


Table of Contents

1. Preamble
2. The File Header
3. Indendation
4. Whitespace
5. Naming of Variables
6. Naming of Functions
7. Blocks and Braces
8. if-then-else, while, etc.
9. Comments
10. Other Habits

Abstract

Any fool can write code that a computer can understand.
Good programmers write code that humans can understand.

    Martin Fowler in: Refactoring, improving the design of existing code

Having multiple developers working on the same source code creates a need for a basic set of coding rules to adhere to. A proper code layout makes it a lot easier for others to read, understand, enhance, debug, and clean-up code.

Having a coding style is quite common. Two of the more prominent examples are The Linux kernel coding style /usr/src/linux/Documentation/CodingStyle and the GNU coding standard http://www.gnu.org/prep/standards/.

1. Preamble

This document describes how to layout code written in YCP: how to name your variables and functions, how to place braces, and how to indent blocks.

Most programmers have a personal style of writing code. The rules presented here might not match your personal preferences, but will help everyone work on the code as a team. Helping out and fixing bugs is easier with a common coding style.

The following set of rules tries to be complete, but probably isn't. Feel free to write the maintainer, lukas.ocilka@suse.cz, about mistakes and omissions.

These rules should apply to C, C++, and YCP code alike, even though the examples use YCP. As much as possible, additionally apply them to Perl code.