0
0
Software Engineeringknowledge~20 mins

DRY (Don't Repeat Yourself) in Software Engineering - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DRY Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the core idea of DRY

What is the main purpose of the DRY principle in software development?

ATo repeat code in different places to make debugging easier.
BTo write as many lines of code as possible for clarity.
CTo avoid writing the same code or logic multiple times by reusing it.
DTo create multiple copies of code for backup purposes.
Attempts:
2 left
💡 Hint

Think about how repeating code affects maintenance and errors.

🚀 Application
intermediate
2:00remaining
Applying DRY to reduce code duplication

You have two functions that calculate the area of a rectangle and a square separately, but both use the same multiplication logic. How can you apply DRY to improve this?

AKeep both functions separate to avoid confusion.
BCreate a single function that takes length and width as parameters and use it for both shapes.
CCopy the multiplication logic into a third function and call it inside both functions.
DWrite the multiplication logic directly inside the main program instead of functions.
Attempts:
2 left
💡 Hint

Think about how one function can handle both shapes by using parameters.

🔍 Analysis
advanced
2:00remaining
Identifying DRY violations in code

Which of the following code snippets violates the DRY principle the most?

Software Engineering
def greet_morning():
    print('Good morning!')

def greet_evening():
    print('Good evening!')

def greet_night():
    print('Good night!')
AEach function repeats the print statement with only the greeting text changed.
BAll functions use a single print statement with different parameters.
CFunctions are combined into one with a parameter for the greeting.
DThere is no repetition; each function is unique.
Attempts:
2 left
💡 Hint

Look for repeated code blocks that differ only slightly.

Comparison
advanced
2:00remaining
Comparing DRY with WET (Write Everything Twice)

Which statement best explains the difference between DRY and WET principles?

ADRY encourages code reuse to avoid duplication, while WET accepts duplication and repeats code.
BDRY means writing code twice for safety, WET means writing code once.
CDRY and WET are the same principles with different names.
DWET is a modern replacement for DRY focusing on code repetition.
Attempts:
2 left
💡 Hint

Think about what each acronym stands for and their goals.

Reasoning
expert
3:00remaining
Reasoning about DRY in large projects

In a large software project, which of the following is a potential downside of strictly applying DRY everywhere without careful design?

AIncreased number of bugs due to code duplication.
BHaving too many repeated code blocks making the project larger.
CSlower program execution because of repeated code.
DOverly complex shared code that is hard to understand and maintain.
Attempts:
2 left
💡 Hint

Consider what happens if you try to reuse code too much without clear structure.