Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Guidelines for writing readable code. Parent comment
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:
if (flags & 45676 == 0) {}
if (flags & ROLE_ADMIN == 0) {}
pool.setDefaultTimeoutMillis(1000);
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 IMO