0% found this document useful (0 votes)
7 views4 pages

Coding Practices

Uploaded by

khushi.kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Coding Practices

Uploaded by

khushi.kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Coding Practices:

Naming Conventions for Various Resources


To enhance readability and maintainability, use the following naming conventions in Python
code:

Class Names
● Use PascalCase for class names.
● Begin each word with a capital letter with no underscores (e.g., UserProfile,
DataProcessor).

Function Names
● Use snake_case for function names.
● Use descriptive, lowercase names with underscores to separate words (e.g.,
calculate_total, get_user_data).

Variable Names
● Use snake_case for variable names, keeping them descriptive and concise.
● Use lowercase letters and underscores for separation (e.g., user_count,
total_amount).

Constants
● Use UPPER_SNAKE_CASE for constants to indicate immutability and importance.
● Use all uppercase letters with underscores separating words (e.g., MAX_RETRY_LIMIT,
DEFAULT_TIMEOUT).

Module and Package Names


● Use lowercase for both modules and packages.
● For multi-word names, separate words with underscores in modules (data_utils.py),
but prefer single-word names for packages (utils, models).

Method Arguments
● Follow the PEP 8 guidelines for method arguments.
● Use descriptive names in snake_case (e.g., file_path, user_id).
● Avoid single-character names unless for specific contexts (e.g., i for indexing).

Exception Naming
● Use PascalCase for custom exception classes, ending with “Error” for clarity (e.g.,
DataValidationError, FileNotFoundError).

Indentation and Spacing


● Use 4 spaces for indentation.
● Keep lines under 79 characters as per PEP 8.
● Use blank lines to separate classes and functions, and single blank lines to separate
logic within functions.

5. Resource Naming Conventions


Consistent naming conventions for databases, tables, AWS resources, Git branches, and
commit messages can prevent ambiguity and make navigation easier across your project.

Database and Table Naming Conventions


● Database Names:
○ Use lowercase letters and avoid special characters.
○ Use snake_case for multi-word names (e.g., customer_data,
analytics_db).
○ Keep names descriptive yet concise (e.g., user_db, sales_reporting).
● Table Names:
○ Use singular nouns in snake_case (e.g., customer, order,
product_inventory).
○ Prefix table names if needed for clarity (e.g., stg_user_data for staging
tables).
● Column Names:
○ Use snake_case for multi-word column names, all in lowercase.
○ Avoid abbreviations unless they are widely understood (e.g., first_name,
order_date, user_id).
● Primary Keys and Foreign Keys:
○ Use id as the primary key for primary key columns.
○ For foreign keys, specify the related table, followed by _id (e.g., user_id,
product_id).

AWS Resource Naming Conventions


To maintain consistency across AWS resources, use a structured naming pattern:

● General Format: {environment}-{service}-{resource}-{identifier}


○ environment: Use short labels like dev, prod, test.
○ service: Define the AWS service being used (e.g., ec2, s3, lambda).
○ resource: Describe the purpose of the resource (e.g., database, function,
bucket).
○ identifier: Use short and unique identifiers (e.g., logs, data).

Examples:

● S3 Bucket: prod-logs-backup
● Lambda Function: dev-function-data_processor
● EC2 Instance: test-db-instance

Specific AWS Resources

● S3 Buckets: env-application-purpose (e.g., prod-sales-data)


● IAM Roles: env-service-role-type (e.g., dev-lambda-execution-role)
● Security Groups: env-vpc-purpose (e.g., prod-vpc-inbound-traffic)

Git Branch Naming Conventions


Define branch naming to clearly communicate the branch’s purpose:

● Feature Branch: feature/short-description


○ For new features or modules, start with feature/, followed by a short
description.
○ Example: feature/user-authentication.
● Bugfix Branch: bugfix/issue-description
○ For bug fixes, start with bugfix/, followed by a description.
○ Example: bugfix/cart-page-error.
● Hotfix Branch: hotfix/critical-fix
○ For critical or urgent fixes on production code, use hotfix/.
○ Example: hotfix/server-crash.
● Release Branch: release/version
○ Use release/ for a new production version.
○ Example: release/v2.1.
● Documentation Branch: docs/section-update
○ Use docs/ for branches updating project documentation.
○ Example: docs/api-reference-update.

Other Naming Conventions


Folder and File Names

● Use snake_case for file and folder names, avoiding special characters and spaces.
● Keep names descriptive yet concise for ease of navigation (e.g.,
data_processing.py, config_loader.py).

Environment Variables
● Use UPPER_SNAKE_CASE for environment variables.
● Prefix with a descriptor to indicate their environment or purpose (e.g., DB_HOST,
API_KEY, AWS_REGION).

Log Files

● Use lowercase with hyphens to separate words.


● Include relevant metadata such as date for easy reference (e.g., app-logs-2024-11-
01.log).

In short

Resource Naming Convention Example

Python Class PascalCase DataProcessor

Python Function snake_case calculate_total

Python Constant UPPER_SNAKE_CASE MAX_USERS

Database Name snake_case analytics_db

Table Name snake_case, singular noun customer_data

AWS Resources env-service-resource-identifier dev-s3-bucket-logs

Git Feature Branch feature/short-description feature/user-


authentication

You might also like