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 Weird and The Wonderful
  4. A real gem.

A real gem.

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++rubyquestion
5 Posts 3 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.
  • T Offline
    T Offline
    Tom Delany
    wrote on last edited by
    #1

    Here's a gem I found in some C++ legacy Windows code I am starting to have to maintain:

    if (hWnd ? hWnd == pWndAppts->m\_hWnd : pWndAppts)
    	pWndAppts->DeleteSelected();
    else if(hWnd ? hWnd == pWndNotes->m\_hWnd : pWndNotes)
    	pWndNotes->DeleteSelected();
    

    pWndNotes and pWndAppts are class pointers (the exact specifics are unimportant). hWnd is, well, an HWND. Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late). :doh: Someone obviously thought they were very clever. :sigh:

    P L 2 Replies Last reply
    0
    • T Tom Delany

      Here's a gem I found in some C++ legacy Windows code I am starting to have to maintain:

      if (hWnd ? hWnd == pWndAppts->m\_hWnd : pWndAppts)
      	pWndAppts->DeleteSelected();
      else if(hWnd ? hWnd == pWndNotes->m\_hWnd : pWndNotes)
      	pWndNotes->DeleteSelected();
      

      pWndNotes and pWndAppts are class pointers (the exact specifics are unimportant). hWnd is, well, an HWND. Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late). :doh: Someone obviously thought they were very clever. :sigh:

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      Yuck.

      Tom Delany wrote:

      Someone obviously thought they were very clever.

      Maybe they were some intern trying to be a show off?

      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

      1 Reply Last reply
      0
      • T Tom Delany

        Here's a gem I found in some C++ legacy Windows code I am starting to have to maintain:

        if (hWnd ? hWnd == pWndAppts->m\_hWnd : pWndAppts)
        	pWndAppts->DeleteSelected();
        else if(hWnd ? hWnd == pWndNotes->m\_hWnd : pWndNotes)
        	pWndNotes->DeleteSelected();
        

        pWndNotes and pWndAppts are class pointers (the exact specifics are unimportant). hWnd is, well, an HWND. Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late). :doh: Someone obviously thought they were very clever. :sigh:

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        Tom Delany wrote:

        Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late)

        Without knowing the code, their could be the situation that pWndNotes or pWndAppts cannot be NULL if hWnd is not NULL. The converse is not true, hence the extra check.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 4a out now (29 May 2008)

        T 1 Reply Last reply
        0
        • L leppie

          Tom Delany wrote:

          Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late)

          Without knowing the code, their could be the situation that pWndNotes or pWndAppts cannot be NULL if hWnd is not NULL. The converse is not true, hence the extra check.

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          T Offline
          T Offline
          Tom Delany
          wrote on last edited by
          #4

          That might be possible. I still have not gotten familiar enough with the code myself to say for sure, yet. I still think it would not have killed them to use a few more lines of code and written it a bit less obtusely. :mad:

          WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated. There are 10 kinds of people in the world: People who know binary and people who don't.

          L 1 Reply Last reply
          0
          • T Tom Delany

            That might be possible. I still have not gotten familiar enough with the code myself to say for sure, yet. I still think it would not have killed them to use a few more lines of code and written it a bit less obtusely. :mad:

            WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated. There are 10 kinds of people in the world: People who know binary and people who don't.

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            Tom Delany wrote:

            I still think it would not have killed them to use a few more lines of code and written it a bit less obtusely.

            Probably. :)

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            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