Hacker News new | past | comments | ask | show | jobs | submit login

Let's call that a "natural constant": while not strictly coming from nature, it is coming from a very familiar and widespread convention.

There are other numbers like that (12, 24, 60 come to mind; 365 has a similar familiarity but has lots of gotchas; I am sure many developers will immediately understand 1024 too).

But that's also mostly due to how they will be used. Contrast and compare:

— a = b * 24

— a = b * HOURS_PER_DAY

— uptime_in_hours = 24 * uptime_in_days

I like the last one best, but if given a choice between the first or the second, I'd prefer to be reading the second.

FWIW, I am not advocating for use of units in variable names at all times — but if you are converting between units, put them in either your variable or constant names.

Basically, I interpret the rule of no-literals as a reminder to think of the readibility of any statement involving them.




> Basically, I interpret the rule of no-literals as a reminder to think of the readibility of any statement involving them.

Now that is an excellent rule, if slightly too specific.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: