CS FundamentalsVery hardProduct-company design interview

Two functions contain the same three lines of code, but one computes a GST rate and the other a delivery charge that happens to use the same formula today. Should they be merged under DRY?

  1. A. Yes, DRY forbids any duplicated lines
  2. B. No: DRY is about duplicated knowledge; if the two rules can change independently, merging couples unrelated concepts and the shared code will soon need flags
  3. C. Yes, because it reduces line count
  4. D. No, because DRY applies only to databases

Correct answer: B. No: DRY is about duplicated knowledge; if the two rules can change independently, merging couples unrelated concepts and the shared code will soon need flags

Coincidental duplication is not the same as duplicated knowledge. Merging them creates a shared function that must change for two different reasons, which leads to parameters and flags that make things worse.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic