-
Notifications
You must be signed in to change notification settings - Fork 69
Code Style
PiecePaperCode edited this page Feb 25, 2021
·
2 revisions
Always contribute your changes to develop
branch not master
your code lines should not exceed 80 columns 81 is still okay
assignment
login_link = self.session.get(
url='https://lobby.ogame.gameforge.com/api/users/me/loginLink?',
params={'id': self.server_id,
'server[language]': self.language,
'server[number]': self.server_number,
'clickedButton': 'account_list'}
).json()
list comparisons
levels = [
int(level['data-value'])
for level in bs4.find_all('span', {'data-value': True})
]
if else statements
if account['server']['number'] == self.server_number \
and account['server']['language'] == self.language:
loops
for level in bs4.find_all(
'span', {'class': 'level', 'data-value': True}
)
constructors init
def __init__(
self,
universe,
username,
password,
token=None, user_agent=None, proxy='',
language=None, server_number=None
):
when ever possible try to not return None and do None checks somewhere else down the line.
- dont do
if condition else None
- do
assert condition, "it failed because condition was not met"
This will catch parsing errors when ogame changes there html and the lib will fail at the line where the parsing error occurred and not in another function that uses the condition.
The code should express itself without the help of an comment.
- To Do Comments should be issues. Create an issue and name it TODO and assign it yourself and track your progress there.
- Doc Strings should be documented in the ReadMe.md
- if you have an weird use case you can point it out in an comment
- dont use generic names like manager, component, data
- variables can be camelCase or _ separated
- Classes begin with a Capital Letter
- use expressive variables names planet_id not pid
Functions or classes can call other functions and parameters but they should not cause side effects. it must be guarantied to run the same every single time it gets called. That means that its forbidden to change variables that are outside of the scope of the function itself.
If you add a new function it needs to be tested in test.py