Is it always good to have DRY(don't repeat yourself) code pattern?
DRY is a software principal which aims to reduce the repition of code means don't repeat your code. Write your code in module, function, methods or classes so that you can use it anywhere anytime, without writing it again and again.
Here is the advantage:
-> You don't have to write code again and again.
-> It take less memory (which we don't bother most of the time).
-> You need to change only at one place, when there is any change in the algorithm.
But here what I experienced:
Let's assume there is large codebase of a social media, there is a function which is performing some task, let's assume creating a comment. Now, this function is used by many users (admin, creator, viewer) to create comment. Here it is best to use DRY code because all users are creating comment in same way, but we want to change some logic of any user there is some headache occurs. Let's assume for 'special user' we want to add functionality to add stickers. Now we have to change basic functionality of comment function.Whenever we are changing something we also need to make sure if everything is working fine for other users as well.
Have you also experienced this?
Would love to hear your opinions.
Top comments (1)
Great explanation!!