Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Coding Conventions

Programming Regulations — Faculty of Information Technology, University of Science, VNU-HCM (FIT-HCMUS)

Coding conventions are a set of guidelines for programmers to follow when writing source code. These conventions help make the source code more understandable and maintainable for others, or for the programmers themselves in the future.

These conventions apply to programming work organized by FIT-HCMUS (Faculty of Information Technology, University of Science, VNU-HCM) and cover both C++ and Python coursework. Each rule is illustrated with examples in both languages.

1. Variable Naming

Some variable naming styles:

Remark: both camelCase and snake_case are acceptable in both languages, as long as the style is applied consistently. In Python materials, snake_case follows the PEP 8 recommendation; in C++ coursework, camelCase is the more common choice.

2. Function Naming

3. Naming Other Components

4. Comments

Comments are text written alongside the source code to describe, explain, and provide information to the programmers and the readers. Comments are not executed when compiling and running. Each language provides its own comment types.

In C++:

In Python:

When using comments, the following conventions should be observed:

5. Whitespace

Whitespace helps separate different components of statements and makes the code easier to read.

6. Indentation

Indentation is used to structure commands in the source code. There are two ways to indent — choose one style and apply it consistently:

This also applies to Python, where indentation is syntactic — it determines the block structure of the code. PEP 8 recommends 4 spaces per level.

Here is an example of indentation in C++:

void checkEvenOdd(int number)
{
    // Indentation here
    if (number % 2 == 0)
        cout << number << " is even." << endl;  // Indentation here
    else
        cout << number << " is odd." << endl;   // Indentation here too
}

And the equivalent in Python:

def check_even_odd(number):
    # Indentation here
    if number % 2 == 0:
        print(number, "is even.")   # Indentation here
    else:
        print(number, "is odd.")    # Indentation here too

7. Bracing

In C++, braces ({}) are used to open and close blocks of statements (a collection of multiple statements) grouped into a logical unit. Two bracing styles are accepted — choose one style and apply it consistently:

In Python, there are no braces: a block opens with a colon (:) and is defined by its indentation level (see Section 6). For example:

if condition:
    # Code
else:
    # Code

Body-less placeholders (for example, when a function is not yet implemented) should use the pass statement (or the ... stub literal) — never an empty braced block as in C++:

def not_implemented_yet():
    pass

References

  1. FIT-HCMUS (2024). Overview of Programming Environment and C/C++ Coding Styles. Practice document.

  2. Google C++ Style Guide. https://google.github.io/styleguide/cppguide.html

  3. Monash University. Programming styles. https://www.monash.edu

  4. PEP 8 — Style Guide for Python Code. https://peps.python.org/pep-0008/