Update style guide.

PiperOrigin-RevId: 559743120
Change-Id: I6073911526bef9a9cc72d95122c4e8b9993b22ba
This commit is contained in:
Yuval Tassa
2023-08-24 07:09:40 -07:00
committed by Copybara-Service
parent 1dad5993f0
commit 9255cc58a9
+11 -9
View File
@@ -34,7 +34,7 @@ takes precedence. Additional principles include:
- Follow the [naming conventions](https://mujoco.readthedocs.io/en/latest/programming#naming-convention). - Follow the [naming conventions](https://mujoco.readthedocs.io/en/latest/programming#naming-convention).
- Be sparing with horizontal space: Try to keep lines short, avoid line-breaks - Be sparing with horizontal space: Try to keep lines short, avoid line-breaks
where possble. where possible.
- Be generous with vertical space: Empty lines between code blocks are good. - Be generous with vertical space: Empty lines between code blocks are good.
- Keep names short. - Keep names short.
- Inline comments are part of the code, treat them as such. - Inline comments are part of the code, treat them as such.
@@ -59,7 +59,7 @@ spot such a pattern, feel free to send a PR to update the guide.
Line length is 100 characters. In rare situations, like the collision table at Line length is 100 characters. In rare situations, like the collision table at
the top of the top of
[engine_collision_driver.c](https://github.com/deepmind/mujoco/blob/c8ff7b3d341560e8cc33fbdcaffbcdbc4c32327c/src/engine/engine_collision_driver.c#L36), [engine_collision_driver.c](https://github.com/deepmind/mujoco/blob/c8ff7b3d341560e8cc33fbdcaffbcdbc4c32327c/src/engine/engine_collision_driver.c#L36),
longer lines are alowed for readability. longer lines are allowed for readability.
#### Comments #### Comments
@@ -88,8 +88,8 @@ including for one-line blocks:
```C ```C
// transpose matrix // transpose matrix
void mju_transpose(mjtNum* res, const mjtNum* mat, int nr, int nc) { void mju_transpose(mjtNum* res, const mjtNum* mat, int nr, int nc) {
for (int i=0; i<nr; i++) { for (int i=0; i < nr; i++) {
for (int j=0; j<nc; j++) { for (int j=0; j < nc; j++) {
res[j*nr+i] = mat[i*nc+j]; res[j*nr+i] = mat[i*nc+j];
} }
} }
@@ -108,7 +108,7 @@ before the `else`:
// rotate vector by quaternion // rotate vector by quaternion
void mju_rotVecQuat(mjtNum res[3], const mjtNum vec[3], const mjtNum quat[4]) { void mju_rotVecQuat(mjtNum res[3], const mjtNum vec[3], const mjtNum quat[4]) {
// null quat: copy vec // null quat: copy vec
if (quat[0]==1 && quat[1]==0 && quat[2]==0 && quat[3]==0) { if (quat[0] == 1 && quat[1] == 0 && quat[2] == 0 && quat[3] == 0) {
mju_copy3(res, vec); mju_copy3(res, vec);
} }
@@ -138,11 +138,13 @@ assignments:
} }
``` ```
- Spaces are not allowed around comparison operators in `for` statements and - Spaces are required around comparison operators.
inside array subscripts `[]`. For an example, inspect the `mju_transpose`
implementation above.
- Three empty lines between function declarations. - Spaces are not allowed around operators in array subscripts `[]` or in
variable initialisation in `for` loops. For example, inspect the
`mju_transpose` implementation above.
- Three blank lines are required between function implementations in source files.
#### Variable declarations #### Variable declarations