Replace magic numbers with named constants across all language implementations #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses code maintainability by replacing magic numbers with appropriately named constants across all language implementations in the refactoring kata.
Changes Made
Magic Numbers Replaced
Formatting Constants:
2→PRICE_DECIMAL_PLACESfor currency formatting precision0→WHOLE_QUANTITY_DECIMAL_PLACESfor integer quantity display3→FRACTIONAL_QUANTITY_DECIMAL_PLACESfor fractional quantity displayBusiness Logic Constants:
2→TWO_FOR_OFFER_QUANTITYfor "two for amount" special offers3→THREE_FOR_TWO_QUANTITYfor "three for two" special offers5→FIVE_FOR_OFFER_QUANTITYfor "five for amount" special offers100.0→PERCENTAGE_DIVISORfor percentage discount calculationsLayout Constants:
40→DEFAULT_COLUMN_WIDTHfor receipt formatting1→DEFAULT_ITEM_QUANTITYfor standard item quantities3→DISCOUNT_SPACING_OFFSETfor receipt layout spacingImplementation Details
Each language follows its own conventions for constants:
C++: Used
constexprconstants in the private section for compile-time evaluationC: Used
#definemacros in the header file following C conventionsTypeScript: Used
static readonlyproperties for type-safe class constantsRuby: Used class constants with ALL_CAPS naming convention
Elixir: Used module attributes (
@constant) for immutable compile-time constantsBenefits
Testing
All existing tests continue to pass, confirming that the refactoring maintains backward compatibility:
Fixes #3.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.