Skip to content

YAGNI Principle

You Aren't Gonna Need It - build only what you need, when you need it!

YAGNI Principle: You Aren’t Gonna Need It

Section titled “YAGNI Principle: You Aren’t Gonna Need It”

The YAGNI (You Aren’t Gonna Need It) principle is a core principle of Extreme Programming (XP) that states: “Don’t add functionality until it’s actually needed.”

YAGNI Principle helps you:

  • Avoid over-engineering - Don’t build features you don’t need
  • Save time - Focus on what’s actually needed
  • Reduce complexity - Less code to maintain
  • Faster delivery - Ship working features sooner
  • Flexibility - Add features when requirements are clear
Diagram

Without YAGNI Principle, you might:

  • Over-engineer - Build features that are never used
  • Waste time - Spend time on unnecessary code
  • Increase complexity - More code = more bugs
  • Slower delivery - Takes longer to ship features
  • Harder to change - Unused code gets in the way
Diagram

Let’s see a simple example showing the problem and solution:

The Problem: Building for Future That May Never Come

Section titled “The Problem: Building for Future That May Never Come”
Diagram
over_engineered.py
# ❌ Without YAGNI - Building features you don't need!
class User:
"""Over-engineered user class with features you don't need"""
def __init__(self, name: str, email: str):
self.name = name
self.email = email
# Building for future that may never come
self.preferences = {} # Don't need this yet!
self.social_links = {} # Don't need this yet!
self.subscription_tier = None # Don't need this yet!
self.notification_settings = {} # Don't need this yet!
self.analytics_data = {} # Don't need this yet!
def update_preferences(self, prefs: dict):
# Feature you don't need yet!
self.preferences.update(prefs)
def add_social_link(self, platform: str, url: str):
# Feature you don't need yet!
self.social_links[platform] = url
# ... many more methods for features you don't need
# Problems:
# - Code is complex for no reason
# - Harder to understand what's actually used
# - Wasted time building unused features
# - Harder to maintain unused code
Diagram
yagni_user.py
# ✅ With YAGNI - Build only what you need!
class User:
"""Simple user class - only what you actually need"""
def __init__(self, name: str, email: str):
self.name = name
self.email = email
# That's it! Only what you need right now
def get_name(self) -> str:
return self.name
def get_email(self) -> str:
return self.email
# When you actually need preferences, add them then!
# When you actually need social links, add them then!
# Don't build them "just in case"
# Benefits:
# - Simple and clear
# - Easy to understand
# - Fast to implement
# - Easy to maintain
# - Can add features when actually needed

Here’s a more realistic example:

yagni_api.py
# ❌ Without YAGNI - Building API endpoints you don't need
class UserAPI:
"""Over-engineered API with endpoints you don't need"""
def get_user(self, user_id: int):
# You need this
pass
def create_user(self, user_data: dict):
# You need this
pass
def update_user_preferences(self, user_id: int, prefs: dict):
# You don't need this yet!
pass
def get_user_analytics(self, user_id: int):
# You don't need this yet!
pass
def export_user_data(self, user_id: int):
# You don't need this yet!
pass
# ✅ With YAGNI - Build only endpoints you need
class UserAPI:
"""Simple API - only what you actually need"""
def get_user(self, user_id: int):
# You need this - build it!
pass
def create_user(self, user_data: dict):
# You need this - build it!
pass
# Don't build other endpoints until you actually need them!
# When you need them, add them then.

Apply YAGNI Principle when:

Building new features - Only build what’s needed now
Designing abstractions - Don’t abstract until you see duplication
Adding “nice to have” features - Skip them until actually needed
Premature optimization - Don’t optimize until you have performance issues
Future-proofing - Don’t build for hypothetical future needs

Diagram

Don’t apply YAGNI when:

Clear requirements - If you know you’ll need it soon, build it
Critical infrastructure - Some things need to be built right
Security concerns - Security features should be built proactively
Technical debt - Sometimes you need to fix architecture issues


  • YAGNI Principle = You Aren’t Gonna Need It
  • Build only what you need - Don’t add functionality until needed
  • Avoid over-engineering - Don’t build “just in case”
  • Faster delivery - Ship working features sooner
  • Balance - Don’t confuse YAGNI with poor planning

Remember: YAGNI is about avoiding unnecessary features, not avoiding planning. Build what you need, when you need it! 🎯