The purpose of this article is to explain in simple terms some acronyms used mainly in the context of software development, each representing an important principle or concept.
1. KISS (Keep It Simple, Stupid)
Simplicity triumphs over complexity. Direct and clear codes are better for developing, maintaining, and scaling, turning simplicity into a form of efficiency.
2. DRY (Don’t Repeat Yourself)
Repeating code is an invitation to problems. Keep your logic in one place to avoid errors and facilitate maintenance, ensuring consistency.
A Clear Example of a Problem if DRY Suggestions Are Not Followed:
Imagine an online sales system that uses different functions to calculate the same 10% tax on products like books, electronics, and toys. By using many functions that do the same thing, it becomes more difficult to manage the system and increases the chance of errors. This goes against the idea of DRY, which suggests using less repetition to make the code easier to manage and more reliable.
If we follow the idea of DRY, we will use only one function that calculates the tax for any type of product. This has made the code simpler, easier to maintain, and reduced the chance of something going wrong. If one day you need to change this tax rule, now it’s only in one place, which makes everything more correct and faster.
3. YAGNI (You Aren’t Gonna Need It)
Avoid creating functions that are not essential. Focus on what is really necessary, keeping the code simple and direct. The YAGNI practice is important for two main reasons:
- Time Savings: You stop spending time developing functions that you may never use.
- Cleaner Code: Your code becomes clearer and free of assumptions that often turn out to be wrong.
4. TDA (Tell, Don’t Ask)
The TDA principle suggests avoiding asking the object about its state; instead, tell it what to do based on the decision, that is, tell the object what to do.
Look at the following code.
In the non-adherent “Tell, Don’t Ask” scenario, the code improperly queries the account’s balance to determine the feasibility of a withdrawal, thereby exposing the account’s internal state and violating the principles of encapsulation. The correct design encapsulates this logic within the Account class itself.
When adhering to the “Tell, Don’t Ask” principle, the Account
class’s withdraw
method internally manages the transaction validation logic. It autonomously determines if a withdrawal is permissible without revealing its balance, maintaining the integrity and confidentiality of the account's state.
5. SOLID
SOLID is a set of five fundamental principles of software design in object-oriented programming. These principles guide developers in creating more readable, flexible, and sustainable software systems. These are not rules, but rather suggestions that will facilitate the life cycle of an application and code.
Post a Comment