🔧 AI Nachrichten Debian is Voting on Whether to Allow AI-Assisted Contributions(23.08.2026 um 09:34 Uhr)
🔧 AI Nachrichten The Linux Kernel Is Approaching 2,000 CVEs Per Release(29.08.2026 um 20:00 Uhr)
⚠️ Malware / Trojaner / VirenCitrix Adds a Linux-Powered Escape Hatch For Compromised Windows PCs(30.08.2026 um 17:34 Uhr)
🔧 AI Nachrichten Debian is Voting on Whether to Allow AI-Assisted Contributions(23.08.2026 um 09:34 Uhr)
🔧 AI Nachrichten The Linux Kernel Is Approaching 2,000 CVEs Per Release(29.08.2026 um 20:00 Uhr)
⚠️ Malware / Trojaner / VirenCitrix Adds a Linux-Powered Escape Hatch For Compromised Windows PCs(30.08.2026 um 17:34 Uhr)

🔧 Programmierung 🕛 vor 3 Jahren 4 Min Lesezeit
0

DRY: Don't Repeat Yourself

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

A software engineering principle.






The problem



As a software developer , it's all about finding solutions to problems. Being able to build something that will solve a specific task.

When you are just starting your journey, it will often be around just finding a way to solve a problem, making something work by using a specific language/technology.



But at some point in your journey, it's not only about making it work , it's making sure you can be able to build on top of it; iterate and also allow people to contribute without impeding the work. There is that meme of coming back to the code you wrote a years ago and not understanding anything, I think it speaks to most of us in the software industry.





The Dry Principle that was popularized by the book The Pragmatic Programmer by Andy Hunt and Dave Thomas (That I encourage you to read of course), in that book they state that :




“every piece of knowledge must have a single, unambiguous, authoritative representation within a system.”




Basically , write only once. A rule of thumb is , if you find yourself writing something twice (a knowledge), it should be refactored(a single function, module, Abstract etc) and reused everywhere.



take a look at this example :




CODE
// not DRY

//file 1
export function infoOfRectange(rectange) {
const area = rectangle.length * rectangle.width;

return {
area,
name: rectangle.name
}


//file 2 use the area to compare two rectangle
export function compare_area(rectangle1, rectangle2){
const area_rectangle1 = rectangle1.length * rectangle1.width;

const area_rectangle2 = rectangle2.length * rectangle2.width;

if(area_rectangle2 > area_rectangle2) return `${rectangle2.name} has a greater area than ${rectangle1.name}`

.....
}






Here we have two different function that uses the area of the rectangle, according to the definition, the area here is a knowledge so that knowledge needs to have a single representation.

So in our context , applying the DRY principle means having a single source of truth for that.




CODE
//dry
export function rectangle_area(length, width){
return length * width;
}

//calling that function in `compare_area`

export function compare_area(rectangle1, rectangle2){
const area_rectangle1 = rectangle_area(rectangle1.length, rectangle1.width);

const area_rectangle2 = rectangle_area(rectangle2.length, rectangle2.width);
.....
}









Do not over engineer



Now that we have learned about Dry , One common mistake is over engineering , meaning refactoring when we don't need to, cause in software development every second cost something and also it's not necessary to bring complexity in our system when it's not needed meaning when we don't have duplicate, when a knowledge is only necessary in one place, it's already DRY and thus we don't need to separate everything.
I will refractor this because it could be useful later This statement should be a red flag and as we said above can cause many issue :



  • introducing more complexity


  • introducting more coupling between our features


  • Cost (is it necessary ?, can this time be spent on something else)


This introduce another principle known as KISS (Keep it Simple Stupid). it translates simply to Do not over engineer



If you have some other example or tips , feel free to share them in the comment section, as well as questions :).



You can follow me on twitter : @Guialajr

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
1 Quelle
Bits und so #1022 (Wie Weißbier)
1 Quelle
KI-Agenten entdecken deutsches Wiki als Kommunikationskanal
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten DRY: Don't Repeat Yourself

Thematisch verwandte Begriffe: Dont, Repeat, Yourself · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...