nerdexam
Cisco

200-901 · Question #41

A developer is reviewing a code that was written by a colleague. It runs fine, but there are many lines of code to do a seemingly simple task repeatedly. Which action organizes the code?

The correct answer is B. Using functions, rewrite any pieces of code that are repeated. When code performs the same task repeatedly across many lines, the best practice is to refactor it by extracting the repeated logic into reusable functions (DRY principle - Don't Repeat Yourself). This reduces code duplication, improves readability, and makes maintenance…

Software Development and Design

Question

A developer is reviewing a code that was written by a colleague. It runs fine, but there are many lines of code to do a seemingly simple task repeatedly. Which action organizes the code?

Options

  • ARefactor the code by removing any unnecessary tests
  • BUsing functions, rewrite any pieces of code that are repeated
  • CReverse engineer and rewrite the code logic
  • DModify the code to use loops

How the community answered

(16 responses)
  • A
    6% (1)
  • B
    88% (14)
  • D
    6% (1)

Explanation

When code performs the same task repeatedly across many lines, the best practice is to refactor it by extracting the repeated logic into reusable functions (DRY principle - Don't Repeat Yourself). This reduces code duplication, improves readability, and makes maintenance easier. Removing tests (A) is not an organization strategy and could introduce bugs. Reverse engineering and rewriting (C) is far more disruptive than necessary. Using loops (D) helps with iteration over data but does not address repeated blocks of procedural logic the way functions do.

Topics

#Code Refactoring#Functions#Code Reusability#DRY Principle

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice