This page describes the coding style and naming conventions used in the NEST C++ codebase. All contributions should follow these guidelines to keep the code consistent and readable.
.cpp file. Two blank lines between free functions.clang-format. It is part of the pre-commit hooks. Make sure to set up pre-commit to ensure correct formatting. For more information see the required development toolsSpace after the keyword; spaces inside the test parentheses; braces on their own line:
Binary operators surrounded by one space: a + b. Unary operators: no space between operator and operand: -a. Use the terms not, and, or instead of !, &&, ||.
No space before a semicolon: return a + 3;
Put a line break after the return type. Parameters either all fit on one line, or each goes on its own line:
<cstdio> over <stdio.h>).printf and related functions; use std::cout / std::cerr.static_cast, dynamic_cast, const_cast, reinterpret_cast). Never use C-style casts.const qualifier wherever appropriate, and use it consistently.enum for integer constants rather than #define.nest.h (e.g. nest::float_t instead of float).lower_case_under_lined notation. C/C++ header files use the .h extension; C++ implementation files use .cpp.| Entity | Convention | Example |
|---|---|---|
| Types (classes, structs, enums) | PascalCase | NodeManager |
| Private nested classes/structs | PascalCase_ (trailing underscore) | State_ |
| Functions and methods | snake_case | get_node_id() |
| Member variables | snake_case_ (trailing underscore) | node_id_ |
| Constants and enumerators | UPPER_SNAKE_CASE | MAX_THREAD_NUM |
| Template parameters | PascalCase | ValueT |
| Namespaces | snake_case | nest:: |
| Preprocessor macros | UPPER_SNAKE_CASE with NEST_ prefix | NEST_ASSERT |
Model parameters should follow the notation of Dayan & Abbott (2001) where available, using subscripts indicated by underscores.
| Parameter | Symbol |
|---|---|
| Membrane potential | V_m |
| Resting potential | E_L |
| Input current | I_e |
| Leak current | I_L |
| Threshold | V_th |
| Reset potential | V_reset |
| Capacity / specific capacitance | c_m |
| Capacitance | C_m |
| Membrane time constant | tau_m |
| Synapse time constant | tau_syn |
| Refractory period | t_ref |
| Time of last spike | t_spike |
| Excitatory reversal potential | E_ex |
| Inhibitory reversal potential | E_in |
| Conductance | g |
| Leak conductance | g_L |
| Sodium conductance | g_Na |
| Sodium reversal potential | E_Na |
| Potassium conductance | g_K |
| Potassium reversal potential | E_K |
Common subscript conventions: m membrane, L leak, e extern, th threshold, syn synapse, ref refractory, ex excitatory, in inhibitory.
.h extension, in the same directory as the corresponding .cpp.#ifndef / #define with the pattern <FILENAME>_H (e.g. IAF_COND_ALPHA_H)..cpp files)nest namespace.using namespace in header files.struct only for passive objects that carry data; use class for everything else.public, protected, private) are not indented.inline methods go after the class definition; other methods go in the .cpp file.All public API must be documented with Doxygen comments. Use Doxygen-style comments in header (.h) files only — avoid them in .cpp files. Do not duplicate the code in comments.
Functions and classes should use the multi-line style even for a single-line comment. Use @param, @returns, @throws, @note, @see as appropriate.
Implementation details that are not part of the public contract belong in regular // comments inside the function body.
NEST_ASSERT (not assert) for internal invariants.nest::KernelException or a derived type for recoverable errors originating from the kernel.