top | item 39409841

(no title)

strulovich | 2 years ago

I believe even truly magic numbers don’t need to be extracted in many cases.

Say in some UI code called FooBarItem you suddenly have some call to set padding to 12. People will take this number, put it in constant and name it FOO_BAR_ITEM_PADDING = 12.

This is not better. It’s just jumping more through the code, and whatever is in the name of the constant is easily deductible from the usage pattern.

I learnt that pattern from others and nowadays I see it as useless. If you can add interesting info in the name or comments of the number, don’t bother extracting a constant.

discuss

order

lucianbr|2 years ago

Don't get me started on string constants. OK_LABEL_TEXT = "OK". GET_METHOD = "GET". Bonus points if this is only used in exactly one place.

Is it really difficult to see that these are pointless? If you actually think about what you are writing, that is.