BashOrg и не только
October 18th, 2009
Quick link: http://oe.lv/834
{ forest } хе, у нас в проекте определена константа в которой хранится кол-во секунд в минуте
via bash.org.ru.
Ну как-бе да, довольно логично. Особливо если не использовать характерные для календаря величины 60 и 12.


The point for refactoring “magic number” into a named constant, is how you assign the semantics.
For example, in your snippet, 12 is MONTHS_IN_YEAR. And the real idea is not to extract constant so that you can change it later (naturally, count of months will not change), but to know this number is not going to change… so that somebody coming in later, maintaining the code, does not change the number accidentally without understanding.
The idea is to assign meaning (semantics) to your number. 60 means nothing. SECONDS_IN_MINUTE – you immediately understand that you are calculating some time span.
Sure, on top of article is quote about “we have constant seconds_in_minute” which is quite funny for some people, and “you immediately understand that you are calculating some time span” — about this stuff is my comment below the image – it is logically to use constants and even more if it is not common (in calendar case) numbers, like 60 and 12.
P.S. Very interesting, some english comments in my blog and they aren’t spam :)