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?
- A. Yes, DRY forbids any duplicated lines
- 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
- C. Yes, because it reduces line count
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A class Report depends on ReportFormatter, and ReportFormatter depends on Report to read its data, creating a cyclic dependency between…
- A unit test calls a service that reads the current time with datetime.now() and fails every day after 6 pm. What is the cleanest fix?
- How many of these situations can produce a merge conflict when merging branch B into A from their common ancestor O? 1. A and B changed…
- Feature X takes the 'happy path' through 5 screens. An alternate flow can occur at screen 2 (2 variants) and an exception flow at screen 4…
- A mobile app shows the error rate of a new release, rolled out to 10% of users as a canary, at 1.2% against 0.4% for the old version on…
- Assertion (A): A test suite that mocks every collaborator of every class can pass while the integrated system fails. Reason (R): Mocks…