Replace magic numbers with named constants across all language implementations#17
Open
Replace magic numbers with named constants across all language implementations#17
Conversation
Co-authored-by: nstubbe <20206435+nstubbe@users.noreply.github.com>
…entations 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] Replace magic numbers with named constants
Replace magic numbers with named constants across all language implementations
Sep 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.