Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
# C++ style guide
See also the [C++ codebase README](../../src/README.md) for C++ idioms in the
Node.js codebase not related to stylistic issues.
## Table of contents
* [Guides and references](#guides-and-references)
* [Formatting](#formatting)
* [Left-leaning (C++ style) asterisks for pointer declarations](#left-leaning-c-style-asterisks-for-pointer-declarations)
* [C++ style comments](#c-style-comments)
* [2 spaces of indentation for blocks or bodies of conditionals](#2-spaces-of-indentation-for-blocks-or-bodies-of-conditionals)
* [4 spaces of indentation for statement continuations](#4-spaces-of-indentation-for-statement-continuations)
* [Align function arguments vertically](#align-function-arguments-vertically)
* [Initialization lists](#initialization-lists)
* [CamelCase for methods, functions, and classes](#camelcase-for-methods-functions-and-classes)
* [`snake_case` for local variables and parameters](#snake_case-for-local-variables-and-parameters)
* [`snake_case_` for private class fields](#snake_case_-for-private-class-fields)
* [`snake_case` for C-like structs](#snake_case-for-c-like-structs)
* [Space after `template`](#space-after-template)
* [Memory management](#memory-management)
* [Memory allocation](#memory-allocation)
* [Use `nullptr` instead of `NULL` or `0`](#use-nullptr-instead-of-null-or-0)
* [Use explicit pointer comparisons](#use-explicit-pointer-comparisons)
* [Ownership and smart pointers](#ownership-and-smart-pointers)
* [Avoid non-const references](#avoid-non-const-references)
* [Use AliasedBuffers to manipulate TypedArrays](#use-aliasedbuffers-to-manipulate-typedarrays)
* [Others](#others)
* [Type casting](#type-casting)
* [Using `auto`](#using-auto)
* [Do not include `*.h` if `*-inl.h` has already been included](#do-not-include-h-if--inlh-has-already-been-included)
* [Avoid throwing JavaScript errors in C++ methods](#avoid-throwing-javascript-errors-in-c)
* [Avoid throwing JavaScript errors in nested C++ methods](#avoid-throwing-javascript-errors-in-nested-c-methods)
## Guides and references
The Node.js C++ codebase strives to be consistent in its use of language
features and idioms, as well as have some specific guidelines for the use of
runtime features.
Coding guidelines are based on the following guides (highest priority first):
1. This document.
2. The [Google C++ Style Guide][].
3. The ISO [C++ Core Guidelines][].
In general, code should follow the C++ Core Guidelines, unless overridden by the
Google C++ Style Guide or this document. At the moment these guidelines are
checked manually by reviewers with the goal to validate this with automatic
tools.
## Formatting
Unfortunately, the C++ linter (based on [Google's `cpplint`][]), which can be
run explicitly via `make lint-cpp`, does not currently catch a lot of rules that
are specific to the Node.js C++ code base. This document explains the most
common of these rules:
### Left-leaning (C++ style) asterisks for pointer declarations
`char* buffer;` instead of `char *buffer;`
### C++ style comments
Use C++ style comments (`//`) for both single-line and multi-line comments.
Comments should also start with uppercase and finish with a dot.
Examples:
```cpp
// A single-line comment.
// Multi-line comments
// should also use C++
// style comments.
```
The codebase may contain old C style comments (`/* */`) from before this was the
preferred style. Feel free to update old comments to the preferred style when
working on code in the immediate vicinity or when changing/improving those
comments.
### 2 spaces of indentation for blocks or bodies of conditionals
```cpp
if (foo)
bar();
```
or
```cpp
if (foo) {
bar();
baz();
}
```
Braces are optional if the statement body only has one line.
`namespace`s receive no indentation on their own.
### 4 spaces of indentation for statement continuations
```cpp
VeryLongTypeName very_long_result = SomeValueWithAVeryLongName +
SomeOtherValueWithAVeryLongName;
```
Operators are before the line break in these cases.
### Align function arguments vertically
```cpp
void FunctionWithAVeryLongName(int parameter_with_a_very_long_name,
double other_parameter_with_a_very_long_name,
...);
```
If that doesn't work, break after the `(` and use 4 spaces of indentation:
```cpp
void FunctionWithAReallyReallyReallyLongNameSeriouslyStopIt(
int okay_there_is_no_space_left_in_the_previous_line,
...);
```
### Initialization lists
Long initialization lists are formatted like this:
```cpp
HandleWrap::HandleWrap(Environment* env,
Local