MILLISEC_PER_SEC is never needed
-
Eddy Vluggen wrote:
It's also a nice shortcut, to change the display from msec to sec, just by setting this constant to "0" instead of "1000" :p
Depending on the usage you might then get a "Division by zero" exception / fatal error popup window instead.
-
I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.
cheers Chris Maunder
Relatively speaking, without it, how could you ever know that your MILLISEC_PER_SEC doesn't match mine? :|
-
I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.
cheers Chris Maunder
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.
-
I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.
cheers Chris Maunder
But what about ONE_SECOND_MS ?
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Surely that's a constant?
-
I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.
cheers Chris Maunder
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.
-
I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.
cheers Chris Maunder
-
Or, perhaps it's needed to differentiate in regions where they use an Imperial Second instead of a regular one.
"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
Like a dueling second?
-
Is that a leading question?
-
Is that a leading question?
-
I suppose that's the long and short of it.
-
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
-
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
-
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? Shit." (Near accurate quote.)
-
I blame the Brits for that one.
cheers Chris Maunder
-
Aaaaggghhhh, Magic Number..... "It's supposed to be microseconds? Shit." (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
toConvertToMicroFurlongs
and change the 1000 to 1000000. Everything's still clear.cheers Chris Maunder
-
<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
toConvertToMicroFurlongs
and change the 1000 to 1000000. Everything's still clear.cheers Chris Maunder
I thought you preferred cubits. Here's a webpage for you: Furlongs to Cubits | Kyle's Converter[^]
-
Damn. I was hoping you knew of one! ;)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
U+035E s͞e͞e͞m͞s͞ to work... OH, not sure how it works in HTML....
<sig notetoself="think of a better signature"> <first>Jim</first> <last>Meadors</last> </sig>
-
I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.
cheers Chris Maunder
It depends on what it is used for. It could be set to other values to speed up or slow down the time counting without changing other modules. If you develop PLC virtualizations, emulators or firmware that value may be fundamental instead of useless.
GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
-
I blame the Brits for that one.
cheers Chris Maunder
You'd better blame the french, and the long scale was the original.
Wrong is evil and must be defeated. - Jeff Ello