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. The Back Room
  4. Code Review, puhleeze

Code Review, puhleeze

Scheduled Pinned Locked Moved The Back Room
c++rubycode-review
3 Posts 2 Posters 21 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 Offline
    C Offline
    Chris Meech
    wrote on last edited by
    #1

    Normally, I'm pretty easy going with other people's code, but I tripped across this gem :vegemite: in some MFC code for the CDateTimeCtrl class. The method will never return FALSE and even goes so far as to ensure that under two conditions, the return value is set to TRUE, even though it has been initialised to TRUE. Go figure.

    BOOL CDateTimeCtrl::GetTime(COleDateTime& timeDest) const
    {
    SYSTEMTIME sysTime;
    BOOL bRetVal = TRUE;

    LRESULT result = ::SendMessage(m\_hWnd, DTM\_GETSYSTEMTIME, 0, (LPARAM) &sysTime);
    if (result == GDT\_VALID)
    {
    	timeDest = COleDateTime(sysTime);
    	bRetVal = TRUE;
    	ASSERT(timeDest.GetStatus() == COleDateTime::valid);
    }
    else if (result == GDT\_NONE)
    {
    	timeDest.SetStatus(COleDateTime::null);
    	bRetVal = TRUE;
    }
    else
    	timeDest.SetStatus(COleDateTime::invalid);
    return bRetVal;
    

    }

    Even better the DTM_GETSYSTEMTIME message only ever returns GDT_VALID or GDT_NONE. Or at least that is what the docs say. Interestingly the CTime 'equivalent' method, returns the response to the message. I suspect that the intention was to check the COleDateTime object's status in order to determine what happened in the GetTime call. But if that's the case why make the method BOOL. :confused: :confused: :confused: :confused:

    L 1 Reply Last reply
    0
    • C Chris Meech

      Normally, I'm pretty easy going with other people's code, but I tripped across this gem :vegemite: in some MFC code for the CDateTimeCtrl class. The method will never return FALSE and even goes so far as to ensure that under two conditions, the return value is set to TRUE, even though it has been initialised to TRUE. Go figure.

      BOOL CDateTimeCtrl::GetTime(COleDateTime& timeDest) const
      {
      SYSTEMTIME sysTime;
      BOOL bRetVal = TRUE;

      LRESULT result = ::SendMessage(m\_hWnd, DTM\_GETSYSTEMTIME, 0, (LPARAM) &sysTime);
      if (result == GDT\_VALID)
      {
      	timeDest = COleDateTime(sysTime);
      	bRetVal = TRUE;
      	ASSERT(timeDest.GetStatus() == COleDateTime::valid);
      }
      else if (result == GDT\_NONE)
      {
      	timeDest.SetStatus(COleDateTime::null);
      	bRetVal = TRUE;
      }
      else
      	timeDest.SetStatus(COleDateTime::invalid);
      return bRetVal;
      

      }

      Even better the DTM_GETSYSTEMTIME message only ever returns GDT_VALID or GDT_NONE. Or at least that is what the docs say. Interestingly the CTime 'equivalent' method, returns the response to the message. I suspect that the intention was to check the COleDateTime object's status in order to determine what happened in the GetTime call. But if that's the case why make the method BOOL. :confused: :confused: :confused: :confused:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Did this start in the Rant and Rave forum or was it moved due to it's politically incorrect nature? I believe that this post should have been posted in the Lounge. Traffic is higher and you would have received useful feedback. After all you were just pointing out some pathetic code that ships with MFC. Michael Martin Pegasystems Pty Ltd Australia martm@pegasystems.com +61 413-004-018 "Don't belong. Never join. Think for yourself. Peace" - Victor Stone

      C 1 Reply Last reply
      0
      • L Lost User

        Did this start in the Rant and Rave forum or was it moved due to it's politically incorrect nature? I believe that this post should have been posted in the Lounge. Traffic is higher and you would have received useful feedback. After all you were just pointing out some pathetic code that ships with MFC. Michael Martin Pegasystems Pty Ltd Australia martm@pegasystems.com +61 413-004-018 "Don't belong. Never join. Think for yourself. Peace" - Victor Stone

        C Offline
        C Offline
        Chris Meech
        wrote on last edited by
        #3

        politically incorrect nature LOL :-D Chris

        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