3 ms·
The reverse is also dangerous: when you have the same numeric value doing different jobs in different parts of the code. If they're literals, you've got no clue
by regularfry 7y ago
The reverse is also dangerous: when you have the same numeric value doing different jobs in different parts of the code. If they're literals, you've got no clue whether they should both be changed or not.
- necovek 7y agoThe idea is not to replace your constant 2048 with A_2048_NUMBER. But eg. MAX_BLOCK_SIZE in one place, and STACK_SIZE in another, even if they are the same value today. Of course, if you are repurposing the code to do something new, you need to be extra careful not to use the constant just because "it's the right number". And sure, it sometimes gets tricky, but using literals will not make it any less so.