DRY vs WET Principles — Php Implementation


DRY (Don’t Repeat Yourself)

What is the pros of this principle?

  • Readability
  • Reuse
  • Cost


If the logic of checking permissions was repeated all over the code, it becomes difficult to fix issues that arise in the repeated code. When you fix a problem in one, you could easily forget to fix the problem in other occurrences. Also, if you have to modify the logic, you have to copy-paste all over the place. By having non-repeated code, you only have to maintain the code in a single place. New logic and bug fixes can be made in one place instead of many. This leads to robust and dependable software.




Let’s see some non-dry approach

As you can see there is 3 if condition which checks attributes are isset or not , does it look perfect?

Let’s refactor this into this

So we can reuse checkAttributes method in different place of code base. And we don’t repeat checking process again and again.

WET (Write Everything Twice)

You may say this is my approach and i can find everything in my code base when it is needed. But this will take much more time and effort of you with a nonsense way.


  1. All code should not merge in one. Two function may looks similar but it can be use very different way.
  2. When your code is over-dried , it will ne neither readable nor sustainable.
  3. DRY not only applies on code but also applies on approach, database tables, relations etc.

Hope i can explain this principle in such an understandable way. Thanks for reading my article. Keep your self safe and healthy. See you on next article.



Senior Php Developer | Javascript | Python | Ruby

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store