Skip to content

Comments

Extract hardcoded discount description strings to named constants#31

Draft
Copilot wants to merge 7 commits intomainfrom
copilot/remove-magic-strings
Draft

Extract hardcoded discount description strings to named constants#31
Copilot wants to merge 7 commits intomainfrom
copilot/remove-magic-strings

Conversation

Copy link

Copilot AI commented Feb 20, 2026

Hardcoded discount description strings ("3 for 2", "% off") were scattered throughout shopping cart implementations across 14 languages, violating DRY principles and complicating future changes.

Changes

Extracted magic strings to named constants at the top of each ShoppingCart implementation:

Before:

discount = Discount(p, "3 for 2", -discount_amount)
discount = Discount(p, str(offer.argument) + "% off", -quantity * unit_price * offer.argument / 100.0)

After:

THREE_FOR_TWO_DESCRIPTION = "3 for 2"
PERCENT_OFF_SUFFIX = " % off"

discount = Discount(p, THREE_FOR_TWO_DESCRIPTION, -discount_amount)
discount = Discount(p, f"{offer.argument}{PERCENT_OFF_SUFFIX}", -quantity * unit_price * offer.argument / 100.0)

Implementations Updated

Applied language-appropriate constant patterns across:

  • Python (2 variants): Module-level constants
  • Java: private static final
  • C# (2 variants): private const
  • TypeScript: const
  • Go: Package-level constants
  • Ruby: Class constants
  • Elixir: Module attributes (@)
  • Common Lisp: defconstant
  • Kotlin: Companion object constants
  • PHP: Class constants
  • Swift: Static properties
  • C++: Static constants

Notes

  • Preserved original output formatting (including " % off" with leading space)
  • Dynamic strings ("2 for X", "5 for X") remain parameterized as they include variable amounts
  • No behavioral changes

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 6 commits February 20, 2026 12:15
…tions

Co-authored-by: nstubbe <20206435+nstubbe@users.noreply.github.com>
… and C++ implementations

Co-authored-by: nstubbe <20206435+nstubbe@users.noreply.github.com>
Co-authored-by: nstubbe <20206435+nstubbe@users.noreply.github.com>
Co-authored-by: nstubbe <20206435+nstubbe@users.noreply.github.com>
…atting

Co-authored-by: nstubbe <20206435+nstubbe@users.noreply.github.com>
Co-authored-by: nstubbe <20206435+nstubbe@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor codebase to clean up magic strings Extract hardcoded discount description strings to named constants Feb 20, 2026
Copilot AI requested a review from nstubbe February 20, 2026 12:28
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

Successfully merging this pull request may close these issues.

2 participants