Skip to content

Commit

Permalink
Add coding guideline
Browse files Browse the repository at this point in the history
Added a coding guideline to be applied to the repository.
  • Loading branch information
phiwuu committed Oct 8, 2024
1 parent dda6fda commit 2072109
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
69 changes: 69 additions & 0 deletions CODING_GUIDELINE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Coding Guideline

We mostly follow the [_Black_ Code Style](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html).

## Classes

The nomenclature of classes shall adhere to the following guideline:

- Classes shall use the CamelCase pattern.
- File names shall be equal to the class names, but all lower case letters.
- Private members shall have at least one leading underscore.
Refer to [Private variables and name mangling](https://docs.python.org/3/tutorial/classes.html#private-variables)
to read more about it.

Example:
```python
class CamelCase:
pass
```
Here the file shall be named `camelcase.py`.

In general, files should not be too lengthy.
We don't want to give a specific limit on the number of lines.
Consider to keep classes in separate files,
instead of having one large file for multiple classes.

## Tests
We are using the `unittest` test framework for unit tests.
Test class names shall consist of the name of the class under test,
with a `Test` postfix.

Example:
```python
from unittest import TestCase

class CamelCaseTest(TestCase):
def test_function1(self):
instance_under_test = CamelCase()
result = instance_under_test.function1()
self.assertEqual(True, result)
```

The file name shall be `test_camelcase.py`

## Line Length
The line length is 88 characters.

## Architecture
Consider to create classes with dedicated properties over using dictionaries with keys.

Example of the preferred approach:
```python
from dataclasses import dataclass


@dataclass
class Car:
color: str

car = Car(color="red")
```

Counter-example of the disfavoured approach:
```python
car = {"color": "red"}
```
The latter examples with a dictionary is easier to get started with,
but it is harder to maintain and refactor.
Also pylint will not be able to give warnings when accessing a key that does not exist.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The individual packages that `bmw-lobster` depends on are:
### For LOBSTER developers

* [Code Coverage Report](https://bmw-software-engineering.github.io/lobster/htmlcov/index.html)
* [Coding Guideline](CODING_GUIDELINE.md)

## Planned inputs

Expand Down
3 changes: 3 additions & 0 deletions pylint3.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ reports=yes
[BASIC]
class-rgx=([A-Z]+|[A-Z][a-z]+)(_[A-Z]+|[A-Z][a-z])*
good-names=i,j,k,c,f,fd,zf,n,ap,rv,sm,mh,wp,ok,db,nc,cc,nt,ct

[FORMAT]
max-line-length=88

0 comments on commit 2072109

Please sign in to comment.