4 ms·
I’m assuming the alternative would be to refer to an easy to deduct constant reference.
by monadic2 6y ago
I’m assuming the alternative would be to refer to an easy to deduct constant reference.
- klyrs 6y agoYou might have replied before my edit, but one rarely "deduces" magic constants that result in good rngs, hashes, crypto, etc.
- __s 6y agoTheir point is you should have const int MAGIC_THING = 0xdeadbeef & then say MAGIC_THING throughout the code, rather than using 0xdeadbeef in all your expressions
- klyrs 6y agoSure. But OP said not to use numeric literals, which 0xdeadbeef certainly is.
- wpietri 6y agoIn case you somehow haven't figured it out by now, he meant in the body of one's code. He's fine with named constants. Protip: If a smart person says something that seems obviously dumb to you, it's worth trying to find an interpretation that isn't dumb. Doubly so when, as here, it's from a piece that others are clearly finding smart and useful.
- monadic2 6y agoAck, it autocorrected from “dedupe”. Also, you are referring to an orthogonal problem—you would presumably want to put magic constants into a static constant to reduce the chances of disagreement across references. Hell even if there’s a single usage I would expect magic constants to be clearly demarcated and documented. Edit: didn’t see sibling constant, didn’t mean to dupe the reply itself. This certainly refers to in-line use of numeric literals vs those used in constant definitions.