Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. MILLISEC_PER_SEC is never needed

MILLISEC_PER_SEC is never needed

Scheduled Pinned Locked Moved The Lounge
76 Posts 31 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Chris Maunder

    I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.

    cheers Chris Maunder

    D Offline
    D Offline
    David ONeil
    wrote on last edited by
    #42

    Relatively speaking, without it, how could you ever know that your MILLISEC_PER_SEC doesn't match mine? :|

    The forgotten roots of science | C++ Programming | DWinLib

    1 Reply Last reply
    0
    • C Chris Maunder

      I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.

      cheers Chris Maunder

      J Offline
      J Offline
      Joe Woodbury
      wrote on last edited by
      #43

      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.

      C 1 Reply Last reply
      0
      • C Chris Maunder

        I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.

        cheers Chris Maunder

        S Offline
        S Offline
        Super Lloyd
        wrote on last edited by
        #44

        But what about ONE_SECOND_MS ?

        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

        1 Reply Last reply
        0
        • P PIEBALDconsult

          Surely that's a constant?

          K Offline
          K Offline
          kalberts
          wrote on last edited by
          #45

          Constants ain't. Variables won't.

          1 Reply Last reply
          0
          • C Chris Maunder

            I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.

            cheers Chris Maunder

            K Offline
            K Offline
            kalberts
            wrote on last edited by
            #46

            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.

            C 1 Reply Last reply
            0
            • C Chris Maunder

              I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.

              cheers Chris Maunder

              K Offline
              K Offline
              kalberts
              wrote on last edited by
              #47

              But we really need a constant - or is that a variable? - ZEROES_IN_ONE_BILLION.

              P C 2 Replies Last reply
              0
              • W W Balboos GHB

                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

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #48

                Like a dueling second?

                1 Reply Last reply
                0
                • K kalberts

                  But we really need a constant - or is that a variable? - ZEROES_IN_ONE_BILLION.

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #49

                  Is that a leading question?

                  K 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Is that a leading question?

                    K Offline
                    K Offline
                    kalberts
                    wrote on last edited by
                    #50

                    Consider it as a "Constants ain't, varaiables won't" sample.

                    P 1 Reply Last reply
                    0
                    • K kalberts

                      Consider it as a "Constants ain't, varaiables won't" sample.

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #51

                      I suppose that's the long and short of it.

                      1 Reply Last reply
                      0
                      • J Joe Woodbury

                        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.

                        C Offline
                        C Offline
                        Chris Maunder
                        wrote on last edited by
                        #52

                        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

                        J K 2 Replies Last reply
                        0
                        • K kalberts

                          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.

                          C Offline
                          C Offline
                          Chris Maunder
                          wrote on last edited by
                          #53

                          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

                          K 1 Reply Last reply
                          0
                          • C 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

                            J Offline
                            J Offline
                            Joe Woodbury
                            wrote on last edited by
                            #54

                            Aaaaggghhhh, Magic Number..... "It's supposed to be microseconds? Shit." (Near accurate quote.)

                            C 1 Reply Last reply
                            0
                            • K kalberts

                              But we really need a constant - or is that a variable? - ZEROES_IN_ONE_BILLION.

                              C Offline
                              C Offline
                              Chris Maunder
                              wrote on last edited by
                              #55

                              I blame the Brits for that one.

                              cheers Chris Maunder

                              J 1 Reply Last reply
                              0
                              • J Joe Woodbury

                                Aaaaggghhhh, Magic Number..... "It's supposed to be microseconds? Shit." (Near accurate quote.)

                                C Offline
                                C Offline
                                Chris Maunder
                                wrote on last edited by
                                #56

                                <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

                                J 1 Reply Last reply
                                0
                                • C 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 to ConvertToMicroFurlongs and change the 1000 to 1000000. Everything's still clear.

                                  cheers Chris Maunder

                                  J Offline
                                  J Offline
                                  Joe Woodbury
                                  wrote on last edited by
                                  #57

                                  I thought you preferred cubits. Here's a webpage for you: Furlongs to Cubits | Kyle's Converter[^]

                                  1 Reply Last reply
                                  0
                                  • OriginalGriffO OriginalGriff

                                    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!

                                    J Offline
                                    J Offline
                                    Jim Meadors
                                    wrote on last edited by
                                    #58

                                    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>

                                    1 Reply Last reply
                                    0
                                    • C Chris Maunder

                                      I put it to you that a variable, constant or define named "MILLISEC_PER_SEC" is never, ever, ever needed.

                                      cheers Chris Maunder

                                      D Offline
                                      D Offline
                                      den2k88
                                      wrote on last edited by
                                      #59

                                      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

                                      K 1 Reply Last reply
                                      0
                                      • C Chris Maunder

                                        I blame the Brits for that one.

                                        cheers Chris Maunder

                                        J Offline
                                        J Offline
                                        Jorgen Andersson
                                        wrote on last edited by
                                        #60

                                        You'd better blame the french, and the long scale was the original.

                                        Wrong is evil and must be defeated. - Jeff Ello

                                        1 Reply Last reply
                                        0
                                        • C 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

                                          K Offline
                                          K Offline
                                          kalberts
                                          wrote on last edited by
                                          #61

                                          So one hour, 3600 seconds, is 3.6 milliseconds.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups