Definition of constants for 0 and 1

I was wondering if others find it unnecessary to do something like this ...

const double RESET_TIME = 0.0;
timeSinceWhatever = RESET_TIME;

rather than just doing

timeSinceWhatever = 0.0;

Do you find the first example for readability? The argument comes down to using magic numbers, and although 0 and 1 are considered “exceptions” to the rule, I always thought that these exceptions only apply to variable initialization or access to the index. When a number makes sense, it should have a variable associated with its value.

I am wondering if this assumption really is, or if it is just redundant to give 0 a named constant.

+3
source share
8 answers

, , , - .

, , REST_TIME -1,5 - - -? , , 0.0 .

, , , .

+3

, .

, , , RESET_TIME ( , , 1), .

, . , timeSinceWhatever = 0; , timeSinceWhatever = RESET_TIME.

+7

, , , ( ),

timeSinceWhenever = ResetStopWatch();

, , , . , . , :

Temperature groundTemp = Temperature.AbsoluteZero();

, .

+2

, , RESET_TIME - 0.0, . 0.0 - , , RESET_TIME.

+1

, , . , OO, , . , / .

+1

, RESET_TIME , , , .

0

, , . , RESET_TIME , , .

0

. const - . , reset -, const

-1

Source: https://habr.com/ru/post/1726021/


All Articles