|
|
|
|
|
by coldtea
3077 days ago
|
|
>ASCII_A could be set incorrectly, or have a dumb type, and is more verbose anyway. By using the character directly, the code speaks its purpose. I disagree. ASCII_A speaks it's purpose (we purposefully want an ASCII A stored here). And one can check the constant's definition, and immediately tell if it's correct. E.g. const ASCII_A = 'A' // correct
const ASCII_A = 'E' // wrong
So: return x >= ASCII_A
tell us the intention of the code's author.Whereas: return x >= ‘A’;
only tells us what the code does, which might nor might not be correct (and we have no way of knowing, without some other documentation).So, by those two lines: const ASCII_A = 'E';
(...)
return x >= ASCII_A;
We know what the code is meant to do, AND that it does it wrongly (and thus, we know what to fix).These line, on the other hand: return x >= ‘A’;
tells us nothing. Should it be 'A'? Should it be something else? We don't know. |
|
(If you say it's because it's written twice, well, that's only a valid clue if ASCII_E doesn't happen to be defined too.)