Archived
Created Code style (markdown)
+59
@@ -0,0 +1,59 @@
|
|||||||
|
## Indentation
|
||||||
|
Never use tabs!
|
||||||
|
Use 2 spaces to indent.
|
||||||
|
|
||||||
|
## Quotes
|
||||||
|
Always use double-quotes!
|
||||||
|
Only use single-quotes when the string contains double-quotes that would need to be escaped.
|
||||||
|
|
||||||
|
## Capitalization
|
||||||
|
Do not use camelCase for variable or function names! Use under_score naming.
|
||||||
|
camelCase is okay when used like `import foo.bar.camelCase as camelCase`.
|
||||||
|
|
||||||
|
## Aligning variable assignments
|
||||||
|
In case you have multiple variable assignments, align the equals sign:
|
||||||
|
|
||||||
|
```Python
|
||||||
|
# bad
|
||||||
|
foo = 1
|
||||||
|
foobar = 2
|
||||||
|
a = 3
|
||||||
|
|
||||||
|
# good
|
||||||
|
foo = 1
|
||||||
|
foobar = 2
|
||||||
|
a = 3
|
||||||
|
```
|
||||||
|
|
||||||
|
Pro Tip: Use the AlignTab plugin for Sublime Text!
|
||||||
|
|
||||||
|
## Horizontal spacing
|
||||||
|
Use at least one space left and one space right to equals signs, and one space right to colons.
|
||||||
|
|
||||||
|
## Vertical spacing
|
||||||
|
Leave two empty lines before function definitions. In case you need to use `@hook.something`, add the two lines before that, directly followed by the definition.
|
||||||
|
|
||||||
|
## Meaningful names
|
||||||
|
Give function and variable names meaningful names. If you want to shorten long names, that's fine, but leave a comment on assigment with the actual meaning.
|
||||||
|
|
||||||
|
## Readability
|
||||||
|
Don't create long lines with lots of function calls. Split into multiple lines instead.
|
||||||
|
Also avoid methods with lots of lines. Split into multiple methods instead.
|
||||||
|
|
||||||
|
```Python
|
||||||
|
# bad
|
||||||
|
foo = int(player_data[str(server.getPlayer(args[4]).getUniqueId())]["details"].["last_login"].strftime("%s"))
|
||||||
|
|
||||||
|
# good
|
||||||
|
player = server.getPlayer(args[4])
|
||||||
|
player_id = uid(player)
|
||||||
|
logintime = player_data[played_id]["last_login"]
|
||||||
|
epoch_time = int(logintime.strftime("%s"))
|
||||||
|
```
|
||||||
|
|
||||||
|
## Comments
|
||||||
|
Comments are good!
|
||||||
|
Please comment everything that's non-obious or makes it easier to understand
|
||||||
|
|
||||||
|
## PEP 8
|
||||||
|
Please take a look at [PEP 8 - Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/#code-lay-out) for anything that has not been covered above.
|
||||||
Reference in New Issue
Block a user