Skip to content

Commit 9eddc57

Browse files
author
Sagar Chalise
committed
python naming conventions files
1 parent 60db262 commit 9eddc57

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

docs/python/classes.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
id: classes
3+
title: Classes
4+
sidebar_label: Classes
5+
---
6+
7+
8+
#### Contents...
9+
10+
* Classes names should always be `PascalCase`. i.e. `MyClass`
11+
* Avoid inbuilt names for class.
12+
* Even if you are building datatypes based on inbuilt class use PascalCase. i.e. `MyDict(dict):`
13+
* Describe the class resposibility in name.

docs/python/files.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
id: files
3+
title: Files & Folders
4+
sidebar_label: Files & Folders
5+
---
6+
7+
## Contents...
8+
9+
10+
####Naming Conventions
11+
12+
* Name in `snake_case` or descriptive single words all in **lowercase**. E.g. `helper.py` or `sftp_fetcher.py` or `tools`
13+
* Be explicit and descriptive of their functionality. Donot have short and ambigous file and folder names.
14+
- E.g. `utils.py` or `utils` will describe of utility.
15+
- E.g. `aws_helper.py` will describe helper related to AWS.
16+
* Donot Clash names with inbuilt and famous modules.
17+
- E.g. donot use `requests.py` or `list.py`
18+
* Be consistent when you are naming. Go with one form when choosing singular or plural names. i.e.
19+
- :ballot_box_with_check: `tools`, `utils` or `tool`, `util` :x: `tools`, `util`
20+
* When designing OOP styled files, go for `abstract.py`, `base.py` or `parent.py` like files/folders for abstract classes.

docs/python/functions.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
id: functions
3+
title: Function
4+
sidebar_label: Functions
5+
---
6+
7+
#### 1. Contents...
8+
9+
* `snake_case` or descriptive single word in **lowercase** should be used.
10+
* function names should explain the functionality.
11+
* for bound methods `self` should be used for first argument.
12+
* for class methos `cls` should be used for first argument.
13+
* `decorators` should be named in function convention.

docs/python/variables.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
id: variables
3+
title: Variables
4+
sidebar_label: Variables
5+
---
6+
7+
#### 1. Contents...
8+
9+
* `snake_case` or descriptive word all in **lowercase** for any type of variables except `CONSTANTS`.
10+
* `ALL_CAPS` for constants. `python` doesnot have the concept of constants so this is just a convention.
11+
* Variable Privacy
12+
- `__{variable_name}` if you want something to be private.
13+
- `_{variable_name}` if you want something to be not publicly used or something that may change later.
14+
- `__{variable_name}` are not directly accesible while `_{variable_name}` are. They are just for convention.
15+
* Avoid builtin variable clash. Especially in globals. You can attach `_` as suffix to builtin names if you deem the name necessary for your variable.
16+
- `all` or `id` is very tempting variable names but they are builtin methods in python. Go with `all_` or `id_` for these or better yet choose something else as a name.

0 commit comments

Comments
 (0)