Giter Site home page Giter Site logo

code-guides's Introduction

Hello team, most of you already know some of these things but we've seen a pattern of bad code which mixes up different coding styles and most of it does not belong to the style convention of the language. Example (pep_8) in python. So here is a small python guide.

Python Guide:

  1. Use 4 spaces per indentation level.
  2. Variables and Function names should be lowercase, with words separated by underscores as necessary to improve readability. (snake case)
  3. Imports should usually be on separate lines
# Correct:
import os
import sys

# Wrong
import sys, os

# Correct:
from subprocess import Popen, PIPE
  1. Use type hints when ever you can.

Note: The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as type checkers, IDEs, linters, etc. In other words variable "x" of type string can be assigned to a int value because Python's typing is for code readability there's not type checking in the language.

greeting = "Hello, {}, you're {} years old"

def greet(user, age):
    return greeting.format(user, age)

name = input("Your name?")
age = int(input("How old are you?"))

print(greet(name, age))
greeting = "Hello, {}, you're {} years old"

def greet(user:str, age:int) -> str:
    return greeting.format(user, age)

name:str = input("Your name?")
age:int = int(input("How old are you?"))

print(greet(name, age))
from typing import Dict, List

dict_of_users: Dict[int,str] = {
    1: "Jerome",
    2: "Lewis"
}

list_of_users: List[str] = [
    "Jerome", "Lewis"
]
  1. Avoid using pip freeze > requirements.txt, instead at the time of installing a new module write it into requirements.txt file with exact version and commit it immediately.
  2. Avoid coupling of code, For example a Django app named (accounts) if we want to make it portable and reusable it should be decoupled which means it should not have imports from anywhere except itself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.