A Reactjs coding style guide
This project is maintained by LinuxDevil
The YAGNI principle, which stands for “you ain’t gonna need it,” is a concept in software development that suggests that developers should avoid adding unnecessary features or functionality to their code. The idea behind this principle is that it is often difficult to predict what features or functionality will be needed in the future, and adding unnecessary features can make the code more complex and difficult to maintain. Instead, developers should focus on implementing only the features and functionality that are necessary for the current version of the software, and avoid adding extra features that may not be used. This can help to keep the code simple and focused, and make it easier to maintain and evolve over time.
// Without following the YAGNI principle, we might write a function like this:
function calculateTotalPrice(price: number, quantity: number, taxRate: number, discount: number): number {
const discountAmount = price * quantity * discount;
const taxAmount = price * quantity * taxRate;
return price * quantity + taxAmount - discountAmount;
}
// This function includes a discount parameter, but we may not actually need
// this feature in the current version of the software.
// However, if we follow the YAGNI principle, we can omit the discount parameter
// and simplify the function, like this:
function calculateTotalPrice(price: number, quantity: number, taxRate: number): number {
const taxAmount = price * quantity * taxRate;
return price * quantity + taxAmount;
}
// This new version of the function is simpler, and it does not include the
// unnecessary discount parameter. If we decide that we need a discount feature
// in the future, we can always add it back to the function, but for now it is
// better to keep the code as simple and focused as possible.