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. Other Discussions
  3. Clever Code
  4. What is the size of my log file?

What is the size of my log file?

Scheduled Pinned Locked Moved Clever Code
question
12 Posts 8 Posters 2 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.
  • D DavidNohejl

    Yusuf wrote:

    (long lLength)

    No reference?


    "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

    Y Offline
    Y Offline
    Yusuf
    wrote on last edited by
    #3

    What reference? Exactly my point. I thought the method return the file size, but it does not, because of the lack of reference in the parameter.

    /* I can C */ // or !C Yusuf

    1 Reply Last reply
    0
    • Y Yusuf

      I was looking under a massive code base, and came across the following code. names changes to protect the innocent.:omg:

      bool CLogFile::GetLength(long lLength)
      {
      bool bOk = false;

      ASSERT (m\_bOpened);    
      if (m\_bOpened)
      {
          try
          {
              lLength = (long)m\_cFile.GetLength();            
              bOk = true;
          }
          catch (CFileException\* e)
          {
              e->Delete();
          }
      }
      
      return bOk;
      

      }

      Notice what is returned, even worst is how the exception is handled.:mad:

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #4

      i don't see the problem. the name of the function is "GetLength" - and that's exactly what it does. it Gets the length, and as a bonus, it tells you if the operation succeeded. if you want to learn the length of the file, you should call the "ReturnTheFileLengthToTheCaller" function! ;)

      image processing toolkits | batch image processing | blogging

      Y P 2 Replies Last reply
      0
      • Y Yusuf

        I was looking under a massive code base, and came across the following code. names changes to protect the innocent.:omg:

        bool CLogFile::GetLength(long lLength)
        {
        bool bOk = false;

        ASSERT (m\_bOpened);    
        if (m\_bOpened)
        {
            try
            {
                lLength = (long)m\_cFile.GetLength();            
                bOk = true;
            }
            catch (CFileException\* e)
            {
                e->Delete();
            }
        }
        
        return bOk;
        

        }

        Notice what is returned, even worst is how the exception is handled.:mad:

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #5

        Looks OK to me, given that CFile::GetLength has no way to indicate an error other than throw an exception. OK, the lLength parameter should be a long&, not a long. I haven't checked View/Source to see if you actually typed the "&".

        Stability. What an interesting concept. -- Chris Maunder

        Y 1 Reply Last reply
        0
        • C Chris Losinger

          i don't see the problem. the name of the function is "GetLength" - and that's exactly what it does. it Gets the length, and as a bonus, it tells you if the operation succeeded. if you want to learn the length of the file, you should call the "ReturnTheFileLengthToTheCaller" function! ;)

          image processing toolkits | batch image processing | blogging

          Y Offline
          Y Offline
          Yusuf
          wrote on last edited by
          #6

          It gets the length and then what? dump it. How does the caller know what the length was? what does returning bool tell the caller? The parameter should be a reference, don't you think so?

          /* I can C */ // or !C Yusuf

          C D 2 Replies Last reply
          0
          • M Mike Dimmick

            Looks OK to me, given that CFile::GetLength has no way to indicate an error other than throw an exception. OK, the lLength parameter should be a long&, not a long. I haven't checked View/Source to see if you actually typed the "&".

            Stability. What an interesting concept. -- Chris Maunder

            Y Offline
            Y Offline
            Yusuf
            wrote on last edited by
            #7

            exactly. this code was written way back and I just stumpled up on it. the parameter should have been a reference to long.

            /* I can C */ // or !C Yusuf

            N 1 Reply Last reply
            0
            • C Chris Losinger

              i don't see the problem. the name of the function is "GetLength" - and that's exactly what it does. it Gets the length, and as a bonus, it tells you if the operation succeeded. if you want to learn the length of the file, you should call the "ReturnTheFileLengthToTheCaller" function! ;)

              image processing toolkits | batch image processing | blogging

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

              Chris Losinger wrote:

              and as a bonus, it tells you if the operation succeeded.

              I'd prefer to get the length (or -1) returned.

              1 Reply Last reply
              0
              • Y Yusuf

                It gets the length and then what? dump it. How does the caller know what the length was? what does returning bool tell the caller? The parameter should be a reference, don't you think so?

                /* I can C */ // or !C Yusuf

                C Offline
                C Offline
                Chris Losinger
                wrote on last edited by
                #9

                it was a joke

                image processing toolkits | batch image processing | blogging

                1 Reply Last reply
                0
                • Y Yusuf

                  exactly. this code was written way back and I just stumpled up on it. the parameter should have been a reference to long.

                  /* I can C */ // or !C Yusuf

                  N Offline
                  N Offline
                  NormDroid
                  wrote on last edited by
                  #10

                  Thats why I hate using refs as out parameters, maybe it should return the size or -1 indicating an error, or return the size and throw an exception if size cannot be computed?

                  .net is a box of never ending treasures, every day I get find another gem.

                  1 Reply Last reply
                  0
                  • Y Yusuf

                    It gets the length and then what? dump it. How does the caller know what the length was? what does returning bool tell the caller? The parameter should be a reference, don't you think so?

                    /* I can C */ // or !C Yusuf

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #11

                    Yusuf wrote:

                    what does returning bool tell the caller?

                    It tells the caller whether GetLength() was successful or not.


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    1 Reply Last reply
                    0
                    • Y Yusuf

                      I was looking under a massive code base, and came across the following code. names changes to protect the innocent.:omg:

                      bool CLogFile::GetLength(long lLength)
                      {
                      bool bOk = false;

                      ASSERT (m\_bOpened);    
                      if (m\_bOpened)
                      {
                          try
                          {
                              lLength = (long)m\_cFile.GetLength();            
                              bOk = true;
                          }
                          catch (CFileException\* e)
                          {
                              e->Delete();
                          }
                      }
                      
                      return bOk;
                      

                      }

                      Notice what is returned, even worst is how the exception is handled.:mad:

                      S Offline
                      S Offline
                      Sergio Zykov
                      wrote on last edited by
                      #12

                      One year ago i've discovered the following diamond: Variable names are mine because original was meaningless. void superPupelMegaRobustMethod() { Thread watchdog = new WatchdogThread().start(); ... watchdog.stop(); } .. void run() { // watchdog loop boolean timeElapsed = false; while(true) { if (timeElapsed) () { new Thread() { .... superPupelMegaRobustMethod(); ..... }.start(); } Thread.sleep(1000); timeElapsed = true; } }

                      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