writings/code_lint.md

54 lines
1.1 KiB
Markdown
Raw Permalink Normal View History

2023-05-11 21:36:11 +02:00
# My coding style
For my years of programming in different language I sort of got a coding style in different language that I more or less follows.
The problem is that I'm not really so consistent with it.
## Defining a scope
For Languages that uses Brackets {} or something similar to define their scope,
the opening bracket should be on the same line as the definition and
the closing bracket should be on a separate line.
for instance:
```c
...
bool move(double x, double y){
if(x - y < 0){
x = y;
return false;
}
y = x;
return true;
}
int main(int argc, char *argv[]) {
...
```
but, if the conditional statement before is on multiple line then the openning bracket should be on a new line.
This help differientiate between the condition and the actual scope
for instance:
```java
...
boolean move(Vec2 position){
if(position.blocked &&
position.empty &&
something.else())
{
position.setPos(x, y);
return false;
}
this.position = position;
return true;
}
int main(int argc, char *argv[]) {
...
```