mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Add first draft about coding standards on Aseprite
This commit is contained in:
parent
594fe3fb90
commit
2fe40a2e50
91
docs/CODING_STANDARDS.md
Normal file
91
docs/CODING_STANDARDS.md
Normal file
@ -0,0 +1,91 @@
|
||||
# Coding Standards
|
||||
|
||||
## Basics
|
||||
|
||||
Basic statements:
|
||||
|
||||
```c++
|
||||
void global_function(int arg1, int arg2,
|
||||
int arg3, ...)
|
||||
{
|
||||
int value;
|
||||
const int constValue = 0;
|
||||
|
||||
if (condition) {
|
||||
...
|
||||
}
|
||||
|
||||
for (int i=0; i<10; ++i) {
|
||||
...
|
||||
}
|
||||
|
||||
while (condition) {
|
||||
...
|
||||
}
|
||||
|
||||
do {
|
||||
...
|
||||
} while (condition);
|
||||
|
||||
switch (condition) {
|
||||
case 1:
|
||||
...
|
||||
break;
|
||||
case 2: {
|
||||
int varInsideCase;
|
||||
...
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Namespaces
|
||||
|
||||
Define namespaces with lower case:
|
||||
|
||||
```c++
|
||||
namespace app {
|
||||
|
||||
...
|
||||
|
||||
} // namespace app
|
||||
```
|
||||
|
||||
## Classes
|
||||
|
||||
Define classes with `CapitalCase` and member functions with `camelCase`:
|
||||
|
||||
```c++
|
||||
class ClassName {
|
||||
public:
|
||||
ClassName();
|
||||
virtual ~ClassName();
|
||||
|
||||
int memberVar() const { return m_memberVar; }
|
||||
void setMemberVar();
|
||||
|
||||
protected:
|
||||
void protectedMember();
|
||||
|
||||
private:
|
||||
int m_memberVar;
|
||||
};
|
||||
```
|
||||
|
||||
## C++11
|
||||
|
||||
We are using some C++11 features, mainly:
|
||||
|
||||
* Use `nullptr` instead of `NULL` macro
|
||||
* Use `auto` for complex types, iterators, or when it's variable type
|
||||
obvious (e.g. `auto s = new Sprite;`)
|
||||
* Use range-based for loops (`for (const auto& item : values) { ... }`)
|
||||
* Use template alias (`template<typename T> alias = orig<T>;`)
|
||||
* Use non-generic lambda functions
|
||||
* Use `std::shared_ptr` and `std::unique_ptr` (currently we're using
|
||||
`base::SharedPtr` and `base::UniquePtr` but you should use the STL
|
||||
ones now)
|
||||
* You can use `<atomic>`, `<thread>`, `<mutex>`, and `<condition_variable>`
|
Loading…
x
Reference in New Issue
Block a user