Skip to content

Coding Guidelines

Kantapon Hemmadhun edited this page Nov 6, 2024 · 16 revisions

YumeLink Coding Guidelines

Coding Style

Follow flake8 coding style with

  • flake8
  • flake8-docstring

Example:

def calculate_area(radius):
    """Calculate the area of a circle given its radius.
    
    Args:
        radius (float): The radius of the circle.
    
    Returns:
        float: The area of the circle.
    """
    if radius < 0:
        raise ValueError("Radius cannot be negative")
    return 3.14159 * radius ** 2

coding conventions

DRY - Don't repeat yourself

Avoid duplicating code. If you find yourself repeating similar code in different parts of the project, refactor it into reusable functions, classes, or mixings.

Example:

from django.db import models

class Author(models.Model):
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
    date_of_birth = models.DateField()
    date_of_death = models.DateField(null=True, blank=True)

    def __str__(self):
        return f"{self.first_name} {self.last_name}"

Don't reinvent the wheel

Use built-in libraries and standard functions instead of recreating them. Prefer well-tested third-party libraries for common tasks.

from django.contrib.auth.decorators import login_required

@login_required
def dashboard(request):
    return render(request, 'dashboard.html')
  • Query optimization
  • Error Handling
  • Sensitive data settings
  • Testing
  • Resolve conflicts with group review and merge.
  • issue format
  • merge request format

Clone this wiki locally