|
Of course not. The logical name is: MILLISEC_PER_SEC_1000_SIC
... such stuff as dreams are made on
|
|
|
|
|
Chris Maunder wrote: MILLISEC_PER_SEC
American or UK Seconds?
Michael Martin
Australia
"I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So I had to leave the place as soon as possible."
- Mr.Prakash One Fine Saturday. 24/04/2004
|
|
|
|
|
I once had a customer tell me, "I want this process time to be ten seconds. Ten German seconds. Not American seconds." We all laughed.
|
|
|
|
|
Daylight Saving seconds.
cheers
Chris Maunder
|
|
|
|
|
How fast is your product traveling? You might need a variable for it.
|
|
|
|
|
Check again - in France it may have an alternative value.*
*After all, they don't have a word for 'seventy', 'eighty', or 'ninety'
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
C'mon - quatre vingt dix rolls off the tongue!
(and it's the reason I can only count to 69 in French when I'm drunk. The maths gets too hard)
cheers
Chris Maunder
|
|
|
|
|
Chris Maunder wrote: rolls off the tongue!
(why did you go there?)
It brought to mind french cuisine, crawling off one's tongue (leaving a slime trail).
I hadn't expected this type of treatment from you!
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
It's easier in Switzerland, they use septante, octante, nonante instead of soixante-dix, quatre-vingts, quatre-vingt-dix.
In Belgium they use some bastardised version with septante, quatre-vingt, nonante IIRC.
|
|
|
|
|
Or, perhaps it's needed to differentiate in regions where they use an Imperial Second instead of a regular one.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
|
protects against people who see "Milli-" and think "1,000,000"
|
|
|
|
|
Relatively speaking, without it, how could you ever know that your MILLISEC_PER_SEC doesn't match mine?
|
|
|
|
|
I actually disagree; I often deal with code using second, milliseconds, microseconds and even nanoseconds, sometimes with more than one unit in a function. Having a const (of some sort) declares what conversion was intended.
|
|
|
|
|
A counterargument. Excellent.
My counter-counter argument, and the reason my brain popped:
I would always prefer to have something like
var timeInSeconds = X;
var timeInMilliseconds = timeInSeconds / 1000;
My point is that the 1000 is always 1000. The variables surrounding that should be the ones clearly named. The "1000" can never be anything other than 1000.
At least that's what I think.
cheers
Chris Maunder
|
|
|
|
|
Aaaaggghhhh, Magic Number.....
"It's supposed to be microseconds? Sh*t."
(Near accurate quote.)
|
|
|
|
|
<small pause>
OK. That argument I will accept in that the number may appear in more than one place, making refactoring painful.
Except, except, except: the calculation should only be done in one place:
var variable = ConvertToMilliFurlongs(X);
...
function ConvertToMilliFurlongs(furlongs)
{
return furlongs / 1000;
}
So if it's "Dammit, Janet. It should be microFurlongs" then you rename ConvertToMilliFurlongs to ConvertToMicroFurlongs and change the 1000 to 1000000. Everything's still clear.
cheers
Chris Maunder
|
|
|
|
|
|
So one hour, 3600 seconds, is 3.6 milliseconds.
|
|
|
|
|
But what about ONE_SECOND_MS ?
|
|
|
|
|
But you wouldn't believe how many people talk about 'kWh per hour'
Sure, it could be meaningful if the power varies, but then 'kWh per hour' might vary, too, and cannot be treated as a single value. And lots of people refer to kWh/hour even when the power is constant.
|
|
|
|
|
So:
What if you then had
var kiloWattPerHourPerHour = X;
var kiloWattPerHourPerMinute = kiloWattPerHourPerHour / 60;
Should the 60 be a constant or a literal?
cheers
Chris Maunder
|
|
|
|
|
Eeeeh...
kW per hour per hour? In which situations does that unit occur?
When does kW per hour occur? A constantly rising (or falling) power, at a rate of x kW/h?
And then you want to a unit for how much, in kW, the power has risen in one hour.
You don't want to simply call it kW, these are not 'absolute' kilowatts, but a change in power, and that is a change per hour over a period of an hour, which is a different kind of kW unit.
Then you want the unit of the increase in power for each minute, right?
You come across the strangest units if you look around
When I was a student, we did some filter calculations where I (after years of wondering) saw how a frequency correction could be given by a time value (European FM pre-emphashis is 50 us, US radios use 75 us - or is it the other way around?), but I never got it under my skin; it is just a strange artifact of unit arithmetics!
If you change that 60 to NumberOfMinutesPerHour, the question is: Are these really the same MinutesPerHour as when you measure 'absolute' time progression? Or, do these MinutesPerHour have a slightly different semantics from the wall clock's minutes per hour (similar to a kW value indicating a change in kiloWattPerHourPerHour is different from an instantaneous, or constant, power kilowatt value)? Maybe it should be called NumberOfMinutesPerHourWhenCalculatingChangesInPowerOverTime?
When we updated our programming guidelines, the project leader of our project immediately granted an exception from the 80 char maximum line length: Our rules for how to construct 'const' names (this was K&R C) led to serveral cases of identifiers of length >80.
Finally, there is the famous Xerox Fortran manual quote:
"The primary purpose of the DATA statement is to give names to constants;
instead of referring to pi as 3.141592653589793 at every appearance, the
variable pi can be given that value with a DATA statement and used instead
of the longer form of the constant. This also simplifies modifying the
program, should the value of pi change."
|
|
|
|
|
Member 7989122 wrote: should the value of pi change
Yep - one of my all time favourites that one
cheers
Chris Maunder
|
|
|
|
|
But we really need a constant - or is that a variable? - ZEROES_IN_ONE_BILLION.
|
|
|
|