Skip to content

Coding Guidelines

Sirin Puenggun edited this page Nov 10, 2023 · 4 revisions

Introdution

These guidelines provide coding style recommendations for contributors to this project.

Python Style Rules

General Rule

  1. Indentation: Use tabs; one tab is equivalent to four spaces.

  2. String Quote: You can use either double quotes (") or single quotes (') for strings, but be consistent within the same function or scope.

  3. Line Length: Keep lines to a maximum of 100 characters.

  • Url Comment: You don't need to break URLs into separate lines if they exceed 100 characters.
  • Longer Line: If longer lines make the code more understandable, it's acceptable to keep them that way.

Naming

Type Public Internal
Packages lower_with_under  
Modules lower_with_under _lower_with_under
Classes CapWords _CapWords
Exceptions CapWords  
Functions lower_with_under() _lower_with_under()
Global/Class Constants CAPS_WITH_UNDER _CAPS_WITH_UNDER
Global/Class Variables lower_with_under _lower_with_under
Instance Variables lower_with_under _lower_with_under (protected)
Method Names lower_with_under() _lower_with_under() (protected)
Function/Method Parameters lower_with_under  
Local Variables lower_with_under

Docstring

We will use reStructuredText (reST) format

"""
This is a reST style.

:param param1: this is a first param
:param param2: this is a second param
:returns: this is a description of what is returned
:raises keyError: raises an exception
"""

Type Hinting

Use type hints as much as possible to enhance code usability.

Import Style

Organize your imports in a specific order. Typically, it's recommended to group imports as follows:

  • Standard Library imports
  • Third-party library imports
  • Django-related imports
  • DRF-related imports
  • Your project's custom imports

Wildcard Imports: Avoid using wildcard imports (e.g., from module import *)

Explicit Imports: Import only the specific classes or functions you need from a module rather than importing the entire module.
use from module import MyClass instead of import module.

Code Formatter

We will only format *.js or *.jsx files with Prettier

Clone this wiki locally