Skip to main content

You Aren't Gonna Need It (YAGNI) Principle

Introduction

Landfill Icon

The You Aren't Gonna Need It (YAGNI) principle is a software development principle that states that you should not implement features until they are actually needed. This principle is based on the idea that it is difficult to predict the future, and that adding features that are not currently needed will only add complexity to your codebase.

Trying to future-proof your code by adding features that you think you might need in the future is a bad idea. Business requirements change too quickly, and it is likely that the features you think you will need will never actually be used. This will only add unnecessary complexity to your codebase, making it harder to maintain and extend in the future.

Example

Imagine you are building a simple e-commerce website. You have a requirement to allow users to add items to their shopping cart, and to check out and pay for their items. You decide that you might want to add a feature in the future that allows users to save their shopping cart and come back to it later. You decide to add a "Save Cart" button to the website, even though you don't currently need it.

This violates the YAGNI principle. You are adding a feature that you don't currently need, and that may never actually be used. This will only add complexity to your codebase, making it harder to maintain and extend in the future.

Conclusion

The YAGNI principle is more about how you think about your code than about any specific coding practice. It is about being pragmatic and focusing on the features that are actually needed, rather than trying to predict the future and add features that you think you might need.

Image Credits

Landfill icons created by Uniconlabs - Flaticon