YAGNI

YAGNI - You Ain't Gonna Need It

YAGNI is a principle that suggests that you should only implement features that you need right now and not ones that you think you might need in the future. This principle is especially important in Agile methodologies because it emphasizes that you should focus on delivering working software that meets the current needs of the customer rather than spending time on developing features that may never be used.

Personal Experience

When I first started working as a developer, I was always trying to anticipate what features the customers might need in the future and would try to implement them. However, most of the time, those features were never used, and I ended up wasting a lot of time and effort on them.

Later on, I learned about the YAGNI principle and started implementing only the features that were needed immediately. This approach not only helped me deliver products faster but also made it easier to maintain them because there were fewer unnecessary features to deal with.

Multiple Ways to Implement YAGNI

  • Minimum Viable Product (MVP): One way to implement YAGNI is to create an MVP that includes only the essential features required to meet the customer's immediate needs. This approach allows you to deliver working software quickly and then iterate on it to add more features as required.
  • Incremental Development: Another approach is to break down a larger project into smaller, more manageable increments. This way, you can focus on delivering the most critical features first and then add more as needed.
  • Test-Driven Development (TDD): TDD is a development approach that emphasizes writing tests before writing code. This approach ensures that you only write code that meets the current requirements and helps you avoid adding unnecessary features.

Code Example


    const calculateTotalPrice = (items) => {
      let totalPrice = 0;
      items.forEach((item) => {
        // only add the price of the item if it's in stock
        if (item.inStock) {
          totalPrice += item.price;
        }
      });
      return totalPrice;
    };
    

In the above code example, we are calculating the total price of a list of items. However, we are only adding the price of an item if it's in stock. This approach follows the YAGNI principle because we are only adding the price of an item that we need right now, rather than trying to anticipate what other features we might need in the future.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe