cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
941
Views
8
Helpful
2
Replies

Trivia Tuesday: DRY

Alex Stevenson
Cisco Employee
Cisco Employee

AlexStevenson_0-1690891353512.png

DRY is a software development principle which is also applicable in many other engineering areas, such as automation, configuration, and CI/CD, to name a few. What does the acronym DRY stand for?

 

Call to Action

Make your best guess, no search results please!

Wrong answers are also accepted ; )

1 Accepted Solution

Accepted Solutions

alecvenidadev
Beginner
Beginner

Hey Alex!
From what I learned at my Full-stack course, DRY means Don't Repeat Yourself. In short, this means that if you have code that is repeating certain patterns, syntax, etc. you can make it more legible by refactoring it.

one example off the top of my head--
use a class to not have to repeat the declaration of dictionaries/objects

BAD

pet1 = {"name": "Annie", "species": "Dog"}
pet2 = {"name": "Precious", "species": "Cat"}

DRY

class Pet:
   def __init__(self, name, specie):
        self.name = name
        self.species = species
annie = Pet("Annie", "Dog")
precious = Pet("Precious", "Cat")
etc...

View solution in original post

2 Replies 2

alecvenidadev
Beginner
Beginner

Hey Alex!
From what I learned at my Full-stack course, DRY means Don't Repeat Yourself. In short, this means that if you have code that is repeating certain patterns, syntax, etc. you can make it more legible by refactoring it.

one example off the top of my head--
use a class to not have to repeat the declaration of dictionaries/objects

BAD

pet1 = {"name": "Annie", "species": "Dog"}
pet2 = {"name": "Precious", "species": "Cat"}

DRY

class Pet:
   def __init__(self, name, specie):
        self.name = name
        self.species = species
annie = Pet("Annie", "Dog")
precious = Pet("Precious", "Cat")
etc...

Alex Stevenson
Cisco Employee
Cisco Employee

Exactly @alecvenidadev ,

 

This code will iterate through the object as well:

 

class Pet:
    def __init__(self, name, species):
        self.name = name
        self.species = species

pet1 = Pet("Precious", "Cat")

for attr, value in pet1.__dict__.items():
        print(attr, value)

 

If I save the above code to a Python file and run it, the result will be:

 

name Precious
species Cat

 

 

DRY improves efficiency, including resource utilization, security, and readability.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: