Coding Standard - nsu-loop/nsu-loop-application GitHub Wiki
A coding standard gives a uniform appearance to the codes written by different engineers & improves readability & maintainability. Below is the coding standard which our team will follow:
Indentation
4-Space Indentation & No Tabs
For example:
def student(name, nid, phone, email):
print(name)
def function_name( variable_one, variable_two):
print(variable_one)
Comments
Block Comment
For a small section of code, They are useful when we have to write several lines of code to perform a single action, such as importing data from a file or updating a database entry. They are important as they help others understand the purpose and functionality of a given code block. Start each line with a # followed by a single space.
For example:
# Loop over i ten times and print out the value of i
# new line character
for i in range(0, 10):
print(i, '\n')
Inline Comment
Inline comments explain a single statement in a piece of code. inline comments should be on the same line as the statement they refer to. Separated by two or more spaces from the statement. Should Start inline comments with a # and a single space, like block comments.
For example:
x = 5 # This is an inline comment
Space After a Comma
There should always be a single space after comma
For example:
a = f(1, 2) + g(3, 4)
Naming Convention
##Choosing name: Choosing names for our variables, functions, classes, is to use descriptive names to make it clear what the object represents.
For example:
name = 'John Smith'
first_name, last_name = name.split()
print(last_name, first_name)
Class Name
Class names should normally use the **Pascal Casing ** convention.
For example:
class FriendRequest:
...........
class FriendList:
...........
Exception Name
Because exceptions should be classes, the class naming convention applies here. However, the suffix "Error" on our exception names (if the exception actually is an error) will be used.
Function Name
Function names should be lowercase, with words separated by underscores as necessary to improve readability.def keyword should be used at the beginning of the function name.
For example:
def my_function():
print("Hello from a function")
Variable Names
Method Name
A lowercase word or words. Words are separated with underscores to improve readability. def keyword should be used at the beginning of method name .
For example:
def method_name() :
............
method body
Constant Name
An uppercase single letter, word, or words. Separate words with underscores to improve readability.
For example:
CONSTANT, MY_CONSTANT, MY_LONG_CONSTANT.
Module Name
A short, lowercase word or words. Separate words with underscores to improve readability
For example:
module.py, my_module.py
Imports
Imports should usually be on separate lines.
Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants. Imports should be grouped in the following order:
- Standard library imports.
- Related third party imports.
- Local application/library specific imports.
For example:
import os
import sys
from subprocess import Popen, PIPE
Control Structures
(For making decision , branching )
if /if-else /if-elif /while/for are used with colon and proper indentation and branching and break should be used. Brackets should not be used.
For example:
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
loops:
i = 1
while i < 6:
print(i)
i += 1
File Naming
modules (filenames) should have short, all-lowercase names, and they can contain underscores.
For example:
posts, profiles, find