Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Consolidate Duplicate Conditional Fragments" solution does not address the problem fully #112

Open
grimsa opened this issue Sep 28, 2021 · 0 comments

Comments

@grimsa
Copy link

grimsa commented Sep 28, 2021

See this problem: https://refactoring.guru/consolidate-duplicate-conditional-fragments

The problematic code is:

if (isSpecialDeal()) {
  total = price * 0.95;
  send();
}
else {
  total = price * 0.98;
  send();
}

The proposed solution is:

if (isSpecialDeal()) {
  total = price * 0.95;
}
else {
  total = price * 0.98;
}
send();

yet it still duplicates the logic of calculating the total.

A better solution would be something like this:

total = price * (isSpecialDeal() ? 0.95 : 0.98);
send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant