Added a coding style guide

This commit is contained in:
Veronica K. B. Olsen
2019-11-03 15:55:37 +01:00
parent 33e3b67ba5
commit be78fd201e
2 changed files with 27 additions and 0 deletions
+5
View File
@@ -133,6 +133,11 @@ The different notes can be assigned tags, which the novel files can refer back t
Currently, this information can be used to display a Timeline View of the story, showing where each scene connects to the plot, and which characters, etc. occur in them.
Further features using this meta data will be added in the future.
## Contribution
If you ant to contribute to novelWriter, please follow the coding convention laid out in the [Style Guide](docs/markdown/style.md).
They broadly follow Python PEP8, but there are a few modifications.
## Screenshot
![Screenshot 1](docs/source/images/screenshot.png)
+22
View File
@@ -0,0 +1,22 @@
# Code Style Guide
The source code of novelWriter broadly follows the style guide [PEP8](https://www.python.org/dev/peps/pep-0008/), but with a few modifications and exceptions.
### Source Code Exceptions
* Methods are camelCase, not underscore based.
The reason is partially because of the maintainers personal preference, and partially because that is what Qt5 and PyQt5 uses.
The maintainer generally, across multiple programming languages, uses underscores for defining namespaces.
* The maximum length of a code line is 100 characters, not 79.
The reason for this is that novelWriter is almost entirely made up of classes, meaning nearly all lines of code already have 8 leading spaces.
A 79 character limitation is too strict, and causes too many wrapped lines.
100 characters is suitable for GitHub diff readability, and therefore the preferred limit.
* Aligning code with additional spaces is acceptable in those cases where it improves readability.
Otherwise, the PEP8 standard should be applied.
### Documentation
The documentation does not adhere to the 80 character limit either.
The standard used in documentation is one line break after each sentence.
This is an alternative style that greatly improves readability of diffs as re-wrapping text is not needed when inserting new text in paragraphs.
Instead, the diff will show changes to each sentence.