08-01-2023 05:05 AM
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 ; )
Solved! Go to Solution.
08-02-2023 05:55 PM
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...
08-02-2023 05:55 PM
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...
08-03-2023 04:55 AM - edited 08-03-2023 04:56 AM
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide