Keep Your Code DRY
What's better WET or DRY code?
Obviously, code doesn't absorb moisture so this is sort of a funny concept but there is a very clear answer. Let's jump into what each of these acronyms stand for.
And if you're someone who wants to really improve their code quality, there's no better resource than the book on Clean Code.
Don't Repeat Yourself
DRY stands for Dont Repeat Yourself. It's code that isn't duplicated in multiple places. DRY code is a fundamental principle of good software design as it aims to reduce repetition. This makes it easier for others to understand the codebase and means less code you have to write!
Typically if you come across a block of code that is repeated in multiple places, that's a good opportunity to separate it out and rewrite it as a single unit of code that can be reused or shared.
Write Everything Twice
The opposite of DRY code is indeed WET code. It represents code that repeats or exists in multiple places. It's waaaay harder to maintain since you have to remember everywhere that code exists and update it in multiple places if you need to change it.
WET code might seem like the low-effort approach to get something working, and I totally get it. It's way faster to copy-paste some logic when you need to use it somewhere else.
But I promise you, it will make your work much much more difficult when you have to come back to it. Or worse yet, if you forget to make a change to each repeated instance of that code.
I don't know about you, but I don't like writing bugs and they're not fun to have to fix later. WET code is pretty much a way to purposely and intentionally make a codebase messy and invite future bugs!