Menu

1 / 2

DRY vs WET Code: When Repeating Yourself Is Actually Better

DEV Community: csharp·Ahmed Omeiza·about 14 hours ago
#XPRq3WYn
#devtocsharp#devto#dev#code#abstraction
Reading 0:00
15s threshold

Every developer has heard the advice: "Don't Repeat Yourself."

But what if following that principle too aggressively makes your code harder to maintain?

Sometimes, duplicating a few lines of code is better than creating an abstraction that complicates everything.

This is where DRY vs WET becomes interesting.

What Is DRY Code?

DRY (Don't Repeat Yourself) is a software development principle that encourages developers to avoid duplicating knowledge or business logic across a codebase.

The idea is simple: Every piece of knowledge should have a single, authoritative representation in a system.

Consider this C# example:

public decimal CalculateProductTax ( decimal price ) { return price * 0.075m ; }

public decimal CalculateServiceTax ( decimal price ) { return price * 0.075m ; }

Enter fullscreen mode

Exit fullscreen mode

Both methods implement the same tax calculation.

If the tax rate changes, you must update both methods.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.