Skip to content

Instantly share code, notes, and snippets.

@smarteist
Created September 22, 2026 18:21
Show Gist options
  • Select an option

  • Save smarteist/8413739115948f66f0d2f9b8d1993e6f to your computer and use it in GitHub Desktop.

Select an option

Save smarteist/8413739115948f66f0d2f9b8d1993e6f to your computer and use it in GitHub Desktop.
YAGNI, KISS, and DRY

3 Simple Software Principles: YAGNI, KISS, and DRY

Three useful software principles are YAGNI, KISS, and DRY.

YAGNI: You Aren’t Gonna Need It

Build only what you need right now. Don’t add features just because you might need them later.

public class User {
    private String name;
    private int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

Avoid adding unnecessary fields “just in case.”

KISS: Keep It Simple

Write code that is easy to read and understand. Simple code is easier to maintain and debug.

public static List<Integer> getEvenNumbers(List<Integer> numbers) {
    return numbers.stream()
            .filter(number -> number % 2 == 0)
            .toList();
}

Don’t make code more complicated than necessary.

DRY: Don’t Repeat Yourself

Avoid writing the same logic in multiple places. Put repeated logic in one reusable method.

public static String getProductName(Product product) {
    return product.getName();
}

public static double getProductPrice(Product product) {
    return product.getPrice();
}

A better approach is to access product properties through the object’s existing methods instead of creating unnecessary duplicate logic.

public class Product {
    private String name;
    private double price;

    public String getName() {
        return name;
    }

    public double getPrice() {
        return price;
    }
}

Conclusion

  • YAGNI: Build only what you need.
  • KISS: Keep your code simple.
  • DRY: Avoid repeating code.

Following these principles helps you write cleaner and more maintainable software.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment