mirror of https://github.com/zeldaret/botw.git
Contributing: Add more code style guidelines and reorder sections
This commit is contained in:
parent
5f575cd5ff
commit
586699d7b1
|
|
@ -18,12 +18,37 @@ Using a decompiler is strongly recommended for efficiency reasons. If you have I
|
|||
|
||||
Feel free to join the [Zelda Decompilation](https://discord.zelda64.dev/) Discord server if you have any questions.
|
||||
|
||||
## Language
|
||||
|
||||
This project is written in C++17. (Technically, in a subset of C++17, since Clang 4.0.1 supports most of C++17 but not all of it.)
|
||||
|
||||
Unlike the vast majority of games that are being decompiled in 2021, *Breath of the Wild* is a large modern game that is written in C++. While C and C++ have a similar syntax, C++ is somewhat more complex than C. To avoid getting lost in C++ code, please familiarize yourself with the following basic language concepts *before* decompiling:
|
||||
|
||||
* [namespaces](https://en.cppreference.com/w/cpp/language/namespace)
|
||||
* Instead of using prefixes such as `z_` to avoid name conflicts, C++ code instead relies on namespaces.
|
||||
* [classes](https://en.cppreference.com/w/cpp/language/class), including inheritance, polymorphism, virtual functions
|
||||
* C++ classes/structs are basically C structs on steroids. Notably, C++ classes can contain member functions.
|
||||
* Member functions get an implicit `this` argument, which is passed as if it were the first argument.
|
||||
* [Virtual member functions](https://en.cppreference.com/w/cpp/language/virtual) are member functions that can be overridden in derived classes.
|
||||
* Virtual member functions are usually implemented with a virtual function table or "vtable", which is a table of function pointers.
|
||||
* [const correctness](https://isocpp.org/wiki/faq/const-correctness) for member functions
|
||||
* iterators and range-based for loops (e.g. `for (int i : my_list_of_ints) {}`)
|
||||
|
||||
## Code style
|
||||
|
||||
This project uses clang-format to enforce a consistent coding style. Before opening a PR, please format your code with clang-format and ensure the following guidelines are followed.
|
||||
|
||||
This will allow your contributions to be reviewed more quickly.
|
||||
|
||||
### General
|
||||
|
||||
* Lines should not be longer than 100 characters.
|
||||
* Use 4 spaces to indent.
|
||||
* Use `nullptr`, not `NULL` or `0`.
|
||||
* Only use `auto` if the variable type is obvious, too long to type or if it doesn't matter.
|
||||
* To compare a value against zero, write `if (value == 0)`, not `if (!value)`.
|
||||
* To compare a value against nullptr, either `if (pointer != nullptr)` or `if (pointer)` is fine.
|
||||
|
||||
### Header files
|
||||
|
||||
* Use `#pragma once` for header guards.
|
||||
|
|
@ -169,23 +194,6 @@ This project sometimes uses small hacks to force particular code to be generated
|
|||
|
||||
* `MATCHING_HACK_NX_CLANG`: Hacks for Switch, when compiling with Clang.
|
||||
|
||||
## Writing proper C++
|
||||
|
||||
Unlike most other decompilation projects, this one targets a large modern game that is written in C++. While C and C++ have similar syntax, C++ is somewhat more complex than C and has many more language features. To avoid getting lost in C++ code, please familiarize yourself with the following, preferably *before* decompiling:
|
||||
|
||||
* [namespaces](https://en.cppreference.com/w/cpp/language/namespace)
|
||||
* Instead of using prefixes such as `z_` to avoid name conflicts, C++ code instead relies on namespaces.
|
||||
* [classes](https://en.cppreference.com/w/cpp/language/class), including inheritance, polymorphism, virtual functions
|
||||
* C++ classes/structs are basically C structs on steroids. Notably, C++ classes can contain member functions.
|
||||
* Member functions get an implicit `this` argument, which is passed as if it were the first argument.
|
||||
* [Virtual member functions](https://en.cppreference.com/w/cpp/language/virtual) are member functions that can be overridden in derived classes.
|
||||
* Virtual member functions are usually implemented with a virtual function table or "vtable", which is a table of function pointers.
|
||||
* [const correctness](https://isocpp.org/wiki/faq/const-correctness) for member functions
|
||||
* iterators
|
||||
* range-based for loops
|
||||
* using nullptr instead of NULL
|
||||
* C++11 / C++14 / C++17 features more generally
|
||||
|
||||
## Project tools
|
||||
|
||||
* Check all decompiled functions for issues: `tools/check.py`
|
||||
|
|
|
|||
Loading…
Reference in New Issue