Clean Code_1

Clean Code_1

ยท

2 min read

Table of contents

No heading

No headings in the article.

YAGNI stands for "You Aren't Gonna Need It", which is another principle of Clean Coding. This principle suggests that you should not add any functionality or code to your project unless it is necessary and you are certain that it will be used. In other words, you should not add features that you think might be useful in the future, as it will only add complexity to your code and may never be used.

This principle encourages developers to focus on the requirements and features that are needed for the current project rather than adding unnecessary features. This can help reduce development time, improve code quality, and make it easier to maintain and update the codebase in the future.

Following the YAGNI principle can also help to avoid over-engineering, which is the tendency to add more features and functionality than necessary. This can result in bloated code that is difficult to manage and maintain, and may also increase the likelihood of bugs and errors.

Let's say you're building a simple blog application that only requires a few basic features, such as the ability to create, edit, and delete blog posts. Here's an example of what your models.py file might look like:

from django.db import models

class BlogPost(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

In this example, we only included the fields that are needed to create and manage blog posts. We didn't include any additional fields, such as custom tags or categories, that might not be necessary at this stage.

By following the YAGNI principle and only implementing the features that are currently needed, we can keep our codebase clean and maintainable. If we later decide that we need to add custom tags or categories, we can always update our models at that time.

ย