Coding Standard - Sajid231/Bengali-Newspaper GitHub Wiki

Coding Standard

Coding Standards: Python

Naming Conventions

ASCII Compatibility Identifiers used in the standard library is ASCII compatible.

Package and Module Names

We are using all lowercase names for module names. Underscores can be used in the module name if necessary. Python packages will also have short, all lowercase names but without underscores.

Class Names

We will use the Pascal Casing convention for naming classes.

Type Variable Names

Names of type variables will normally use CapWords preferring short names.

Exception Names

We will use Pascal Casing for defining an Exception class.

Global Variable Names

Modules that are designed for use via from M import * will use the all mechanism to prevent exporting globals, or using the older convention of prefixing such globals with an underscore.

Function and Variable Names

Function names will follow the Pascal Casing. Variable names follow the Snake Casing to improve readability.

Function and Method Arguments

We will use self for the first argument to instance methods. cls for the first argument to class methods.

Method Names and Instance Variables

We will use the function naming rules: lowercase with words separated by underscores as necessary to improve readability.

Also one leading underscore only for non-public methods and instance variables.

To avoid name clashes with subclasses, we will use two leading underscores to invoke Python's name mangling rules.

Constants

Constants will be defined on a module level and will be written in all capital letters with underscores separating words. Examples include MAX_ITEM and TOTAL.

Indentation

We will use 4 spaces per indentation level.

Pet Peeves

For avoiding extraneous whitespace in the following situations:

  • Immediately inside parentheses, brackets or braces.
  • Between a trailing comma and a following close parenthesis.
  • Immediately before a comma, semicolon, or colon

Block Comments

Each line of a block comment starts with a # and a single space (unless it is indented text inside the comment). Paragraphs inside a block comment are separated by a line containing a single #.

Example of Case Type

Example of Case Type