❔ reduce these magic number code smells
Hey there, i have the following code which looks quite identical. How can i clean the magic numbers to remove the code smells?
13 Replies
is the question like "what name should i give them?"
No, what I try to ask is; Since these are all the same over the 3 functions I want to implement something so that these magic numbers can be removed or are like defined once.
it all depends on your needs
they could be constants in the class
they could be methods from a service if they need to be calculated in some way
they could be static properties of a class if they need to be used in multiple places
I would need to make 4 additional constants then, but still, needing to put them on all 3 functions feels still a bit "messy"
that looks a lot like u want a factory method to create the clusters
this code is already in 1 builder tho,
well, make it a private helper method in the builder or so
another way would be to define something like a rectangle or region struct and store these somewhere / make factory methods for each
and then use these to pass to the data to the different GetSub... methods
const int Width = 6;
then
But I don't know the context, so it can be wrongit seems to be like a margin?
no,. i need to build sudokus, and I need to build a samurai sudoku too
but a samurai is very different compared to a regular one
It depends on your needs, but in general the first advice is use
Constants
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.