(no title)
lsadam0 | 7 years ago
I honestly cannot think of a reasonable argument for why constant values should not be in static constants or enums. For one, why would you want to re-type the value over and over? And two, it only takes one typo in one manually typed value to introduce a frustrating bug! It's such an easy bug to avoid and costs almost zero to do correctly! Honestly, devs manually typing values that are effectively consts is one of my biggest pet peeves, you're just creating easily avoidable problems for yourself and your team :).
kevinconaway|7 years ago
My personal opinion is that values should be in constant values if:
- Its repeated more than once or referenced outside of the file
- The constant value is a "magic number" where the meaning of the value isn't obvious to outsider
If the value is used only once and the meaning of the value is clear, I think extracting a constant out is needless indirection.
For example:
is a magic number that definitely should be a constant, even if its only used once: However something like: is perfectly obvious in context IMOlsadam0|7 years ago
codingdave|7 years ago