**WARNING** : this setup only works for Linux and Windows-WSL.
## Setup and Run
In order to setup your C++ project and run it, you must use the following commands :
Create the build output directory (the first time)
```bash
mkdir build
cd build
```
Compile your code
```bash
cmake .. # Re-run everytime you add or remove .hpp & .cpp files, or when you change CMakeLIsts.txt
make # Compile your code
./<executable_name> # Run your compiled program
```
## VSCode Project Settings
## VSCode Project Settings
In order to ensure that everyone uses the same linting and formatting settings,
In order to ensure that everyone uses the same linting and formatting settings,
...
@@ -28,12 +49,11 @@ The [Clangd](https://clangd.llvm.org/) language server is a better language serv
...
@@ -28,12 +49,11 @@ The [Clangd](https://clangd.llvm.org/) language server is a better language serv
## Environment and reproducibility
## Environment and reproducibility
TODO: linux
As c++ does not have a package manager, you must install dependencies by hand. There are 3 ways to install dependencies :
In order to make it easier for other developers to contribute to your project,
- Install using Linux packages : some dependencies are available as Linux packages.
and to enable deploying your application easily, you must indicate which python version and dependencies you are using.
- Install manually to `/usr/local/include` (headers), `/usr/local/lib` (libraries) and `/usr/local/bin` (executables). If you put the relevant dependency folders and executable there, your C++ compiler will find them without any issue.
- Install manually to a random location : you will need to modify your `CMakeLists.txt` in order to tell the compiler where to find the dependencies (more complicated).
You typically indicate the python version in your [`pyproject.toml`](./pyproject.toml) or (`README.md`)(./README.md) file.
### Git
### Git
...
@@ -42,52 +62,24 @@ Some common gitignores for a C++ project :
...
@@ -42,52 +62,24 @@ Some common gitignores for a C++ project :
-`build/` : the build output folder.
-`build/` : the build output folder.
-`.cache/` : clangd cache folder.
-`.cache/` : clangd cache folder.
## Python Clean Code
## C++ Clean Code
TODO : code rules
Some often-overlooked python clean code rules :
Some often-overlooked C++ clean code rules :
### Docstrings
### Docstrings
Always write docstrings in order to describe the purpose of your functions and classes.
Always write docstrings in order to describe the purpose of your functions and classes.
```python
```cpp
deffunction():
/** This function does something */
"""This function does something."""
voidfunction(){
pass
}
```
```
### Type hinting
### Header files
When you can (always), use type hints to indicate the types of the parameters of your functions, their return types, etc...
When your project gets bigger, you must split your code into header (`.hpp`) and source (`.cpp`) files.
You sometimes need to use the `typing` module to indicate more complex types.
The header files contain class and function header declarations, and source files contain the implementations.
```python
- ALWAYS add `#pragma once` at the very top of each of your header files.
fromtypingimportList
- ALWAYS include header files in your code, NEVER include source files.
Since python 3.10, you can use the `|` operator to indicate that a parameter can be of multiple types, and use `list` and `dict` directly as type hints.
When your code gets big, you should split it into multiple files.
Use the following test in order to run module-specific code only when you run your module directly via `python module.py`, and not when you import it from another file.