Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ DRY: Don't Repeat Yourself

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š DRY: Don't Repeat Yourself


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

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.

coming back to the code you wrote

So it's not only about coding , but building something that can last using tools and principles; just like building a car , a house. And that is called Software engineering

On Wikipedia a software engineer is define as

a person who applies the principles of software engineering to design, develop, maintain, test, and evaluate computer software. The term programmer is sometimes used as a synonym, but may also lack connotations of engineering education or skills.

One those principles is called DRY(D'ont Repeat Yourself)

What is DRY ?

do not repeat yourself javascript class

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 :

// 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.

//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

...



๐Ÿ“Œ DRY: Don't Repeat Yourself


๐Ÿ“ˆ 59.14 Punkte

๐Ÿ“Œ Don't Repeat Yourself (App Center/Azure DevOps) | Partly Cloudy


๐Ÿ“ˆ 39.5 Punkte

๐Ÿ“Œ Partly Cloudy: Don't Repeat Yourself (App Center/Azure DevOps)


๐Ÿ“ˆ 39.5 Punkte

๐Ÿ“Œ REPEAT AND REFINE: HOW DO YOU GET TO CARNEGIE HALL? (Pt. 6 of โ€œWhy Donโ€™t You Go Dox Yourself?โ€)


๐Ÿ“ˆ 39.5 Punkte

๐Ÿ“Œ Wet Dreams Don't Dry: Leisure Suit Larry kehrt zurรผck in die Zukunft


๐Ÿ“ˆ 27.76 Punkte

๐Ÿ“Œ Leisure Suit Larry ist zurรผck: Wet Dreams Don't Dry


๐Ÿ“ˆ 27.76 Punkte

๐Ÿ“Œ Wet Dreams Don't Dry im Test: Leisure Suit Larry im Land der Hipster


๐Ÿ“ˆ 27.76 Punkte

๐Ÿ“Œ Leisure Suit Larry: Wet Dreams Don't Dry im Test - Der Schwerenรถter aus den ...


๐Ÿ“ˆ 27.76 Punkte

๐Ÿ“Œ Leisure Suit Larry - Wet Dreams Don't Dry: Schwerenรถter Larry Laffer treibt auch auf Xbox One sein Unwesen


๐Ÿ“ˆ 27.76 Punkte

๐Ÿ“Œ Launch-Trailer zu Wet Dreams Don't Dry: Larry Laffer ist wieder da


๐Ÿ“ˆ 27.76 Punkte

๐Ÿ“Œ Leisure Suit Larry - Wet Dreams Don't Dry is launching on Xbox One today


๐Ÿ“ˆ 27.76 Punkte

๐Ÿ“Œ The AWS DevOps Professional Exam is Exhausting! And Why You Don't Want To Repeat It


๐Ÿ“ˆ 27.21 Punkte

๐Ÿ“Œ Are you team โ€œstare at yourself adoringlyโ€ or team โ€œavoid eye contact with yourself at all costsโ€? ๐Ÿง


๐Ÿ“ˆ 24.58 Punkte

๐Ÿ“Œ Learn How to Protect Yourself From Yourself With Identity Governance and Intelligence


๐Ÿ“ˆ 24.58 Punkte

๐Ÿ“Œ Learn How to Protect Yourself From Yourself With Identity Governance and Intelligence


๐Ÿ“ˆ 24.58 Punkte

๐Ÿ“Œ Apple's Vision Pro Headset: newest way to distance yourself from yourself, and from humanity?


๐Ÿ“ˆ 24.58 Punkte

๐Ÿ“Œ Donโ€™t expose yourself with your boarding pass


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ Donโ€™t Be Catfished: Protecting Yourself From New Account Fraud


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ Don't Give Away Historic Details About Yourself


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ Donโ€™t Fall For the New CryptoBlackmail Scam: Hereโ€™s How to Protect Yourself


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ Donโ€™t Fall for Webcam Blackmail: Hereโ€™s How to Protect Yourself


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ Breaches are like break-ins: Don't wait until after to protect yourself


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ Why Donโ€™t You Go Dox Yourself?


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ COLLECTING OUR BREADCRUMBS (Pt. 2 of โ€œWhy Donโ€™t You Go Dox Yourself?โ€)


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ RESTRICT: LOCKING THE FRONT DOOR (Pt. 3 of โ€œWhy Donโ€™t You Go Dox Yourself?โ€)


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ LOCKING THE BACK DOOR (Pt. 4 of โ€œWhy Donโ€™t You Go Dox Yourself?โ€)


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ CLEANING UP THE CLUTTER (Pt. 5 of โ€œWhy Donโ€™t You Go Dox Yourself?โ€)


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ Don't Do it yourself: Automatisierung mit autonomen Datenbanken


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ Donโ€™t do IT yourself: The trick to ensuring business alignment


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ Don't flatten yourself restoring malware with Control Flow Flattening obfuscation - Geri Revay


๐Ÿ“ˆ 20.41 Punkte

๐Ÿ“Œ Delicious Non-Boozy Beer, Wine, and Spirits for Dry January


๐Ÿ“ˆ 19.64 Punkte

๐Ÿ“Œ How Cities Are Using Dry Ice To Kill Rats


๐Ÿ“ˆ 19.64 Punkte

๐Ÿ“Œ How Cities Are Using Dry Ice To Kill Rats


๐Ÿ“ˆ 19.64 Punkte

๐Ÿ“Œ Delicious Non-Boozy Beer, Wine, and Spirits for Dry January


๐Ÿ“ˆ 19.64 Punkte











matomo