Skip to main content
1 of 2
Vitor Py
  • 4.9k
  • 1
  • 31
  • 34

I'd keep the rule of never having magic numbers.

While

seconds = num_days * 24 * 60 * 60 

Is perfect readable most of the time, after coding 10 hours a day for tree or four weeks when in crunch mode

seconds = num_days * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_HOUR 

is much easier to read. FrustratedWithFormsDesigner suggestion is better:

seconds = num_days * DAYS_TO_SECOND_FACTOR 

or even better

seconds = CONVERT_DAYS_TO_SECONDS(num_days) 

Things stop being obvious when you're very tired. Code defensively.

Vitor Py
  • 4.9k
  • 1
  • 31
  • 34