Tactility/CODING_STYLE.md
Ken Van Hoeylandt 72230129bb
unPhone implementation and more (#169)
- Implemented [unPhone](https://unphone.net/) v9 board
- Updated `.clang-format` to better reflect the intended code style
- Fix SD card compatibility issues for all boards (frequency wasn't set well)
- Moved `I2cDevice` class from CoreS3 board project to TactilityHeadless project
- Tactility configuration now has default empty lists for apps and services fields
- Fix for Launcher app: we don't need padding when showing it vertically
- Fix for I2cDevice read/write calls that checked for `esp_err_t` instead of `bool`
- Fix for TinyUSB init that checked for `esp_err_t` instead of `bool`
2025-01-19 16:57:00 +01:00

1.7 KiB

C++ coding Style

The basic formatting rules are set in .clang-format. Use auto-formatting in your editor.

All code should target C++ language revision 20.

If you use CLion, please enable the setting called "Enable ClangFormat" under Settings > Editor > Code Style.

Naming

Files

Files are upper camel case.

  • Files: ^[0-9a-zA-Z]+$
  • Directories: ^[0-9a-zA-Z]+$

Example:

SomeFeature.cpp
SomeFeature.h

Private/internal headers are postfixed with Private before the file extension. Like SomeFeaturePrivate.h

Folders

Project folders include:

  • Source for source files and public header files
  • Private for private header files
  • Include for projects that require separate header files

Sources for a specific namespace must go into a folder with the lowercase name of that namespace. The only exception to this is the root namespace, as this doesn't require its own subfolder.

Function names

Names are lower camel case.

Example:

void getLimit() {
    // ...
}

Preprocessor

Preprocessor functions are written in snake-case and prefixed with tt_, for example:

#define tt_assert(x) __tt_assert_internal(x)

Type names

Consts are lower camel case with capital letters.

Typedefs for structs, classes and datatype aliases are upper camel case.

Examples:

typedef uint32_t ThreadId;

const ThreadId id;

struct ThreadData {
    // ...
};

Enumerations

enum class or enum struct is preferred over plain enum because of scoping. It's styled like this:

enum class  {
    Ok,
    NotSupported,
    Error
};

Exceptions

Don't ever throw them. Make a return type that wraps all the error and success scenarios that are relevant.