Skip to content
the poor coder

YAGNI

Poor Man
Published
Reading time
2 min read
On this page

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#

JavaScript

    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.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC