Coding Conventions

Each language has its own conventions and idioms. However some principles are universal.

In general, code should be written with the goal of maximizing readability and clarity. Usually this means following the same style as the existing code, if any. Coding conventions exist to resolve some ambiguities with that guidance.

If the language supports a strict mode or an equivalent of -Wall which reports all warnings, this mode be used In the strictest mode, the code should compile without warnings. If there are warnings that are in fact intentional the warnings should be suppressed only where they occur with a #pragma or some other construct, and not disabled categorically.

If the compiler supports a mode that treats warnings as errors and fails the build, that mode should be enabled.

Specific guidance in this book notwithstanding, code should follow the conventions applicable to that code. For example, a Linux device driver and a Mac library might both be written in C or C++, but it’s likely there are very different style conventions used by idiomatic code on those respective platforms.

Some guidance for specific languages follows:

Rust

See the Rust coding conventions chapter for details.

C

The main part of the C code in our project is elastio-snap kernel module.
A good practice for the kernel modules to use Linux kernel coding style. And we'll stick to this practice.

Our repo is a fork of the Dattobd, which already following this code style. However, we'll not change existing code lines that don't match the style, just for the sake of style, until the functionality changes.

The same rules apply to any user-space libraries and utilities developed on C.

C++

C++ developers, to fill out

Go

Our team’s Go coding standards are simple and easily applied. All .go files are to be renamed .rs and modified until they compile cleanly under the Rust compiler.

Javascript

Thankfully Javascript is no longer needed, as Rust and C++ can be compiled to WebAssembly :) If for some reason WebAssembly isn’t an option, then TypeScript will have to do.