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. And Another One

And Another One

Scheduled Pinned Locked Moved The Weird and The Wonderful
jsonquestion
5 Posts 4 Posters 3 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.
  • R Offline
    R Offline
    Rick York
    wrote on last edited by
    #1

    Horror 1 :

    if (strRet[0] == '0' && strRet[1] == '1' &&
    strRet[2] == 'F' && strRet[3] == 'F' &&
    strRet[4] == '2' && strRet[5] == '4')

    A piece of code I just looked at had the preceding logic sprinkled through it around twenty times to examine the response from a piece of equipment with comparisons of varying lengths. Apparently this individual has never heard of strncmp or its TCHAR variant _tcsncmp. Horror 2 : They wrote their own function essentially equivalent to strtoul. I won't subject you all to it - you'll have to trust me when I say that it is a horror. Horror 3 : The function described in Horror 2 is called ConvertHEXASC(). Here's how it is used to convert the data from the equipment :

    int iTmp = 0;	
    iTmp += ConvertHEXASC( strRet\[7\] ) \* 1;      // 16^0
    iTmp += ConvertHEXASC( strRet\[6\] ) \* 16;     // 16^1
    iTmp += ConvertHEXASC( strRet\[5\] ) \* 256;    // 16^2
    iTmp += ConvertHEXASC( strRet\[4\] ) \* 4096;   // 16^3
    

    Now imagine a similar sequence of code used a few dozen times with strings of varying lengths and positions. :omg: Horror 4 : There were sixteen buttons used to select a property for the equipment and, naturally, there were sixteen different functions made to handle the clicks of the buttons. ON_COMMAND_RANGE anyone ? :wtf: The word horror barely scratches the surface for these and the rest of the things I saw there. It was staggering. Simply staggering.

    CPalliniC G 2 Replies Last reply
    0
    • R Rick York

      Horror 1 :

      if (strRet[0] == '0' && strRet[1] == '1' &&
      strRet[2] == 'F' && strRet[3] == 'F' &&
      strRet[4] == '2' && strRet[5] == '4')

      A piece of code I just looked at had the preceding logic sprinkled through it around twenty times to examine the response from a piece of equipment with comparisons of varying lengths. Apparently this individual has never heard of strncmp or its TCHAR variant _tcsncmp. Horror 2 : They wrote their own function essentially equivalent to strtoul. I won't subject you all to it - you'll have to trust me when I say that it is a horror. Horror 3 : The function described in Horror 2 is called ConvertHEXASC(). Here's how it is used to convert the data from the equipment :

      int iTmp = 0;	
      iTmp += ConvertHEXASC( strRet\[7\] ) \* 1;      // 16^0
      iTmp += ConvertHEXASC( strRet\[6\] ) \* 16;     // 16^1
      iTmp += ConvertHEXASC( strRet\[5\] ) \* 256;    // 16^2
      iTmp += ConvertHEXASC( strRet\[4\] ) \* 4096;   // 16^3
      

      Now imagine a similar sequence of code used a few dozen times with strings of varying lengths and positions. :omg: Horror 4 : There were sixteen buttons used to select a property for the equipment and, naturally, there were sixteen different functions made to handle the clicks of the buttons. ON_COMMAND_RANGE anyone ? :wtf: The word horror barely scratches the surface for these and the rest of the things I saw there. It was staggering. Simply staggering.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      What's the background of such champion-of-code-development? Just curious. :-D

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • R Rick York

        Horror 1 :

        if (strRet[0] == '0' && strRet[1] == '1' &&
        strRet[2] == 'F' && strRet[3] == 'F' &&
        strRet[4] == '2' && strRet[5] == '4')

        A piece of code I just looked at had the preceding logic sprinkled through it around twenty times to examine the response from a piece of equipment with comparisons of varying lengths. Apparently this individual has never heard of strncmp or its TCHAR variant _tcsncmp. Horror 2 : They wrote their own function essentially equivalent to strtoul. I won't subject you all to it - you'll have to trust me when I say that it is a horror. Horror 3 : The function described in Horror 2 is called ConvertHEXASC(). Here's how it is used to convert the data from the equipment :

        int iTmp = 0;	
        iTmp += ConvertHEXASC( strRet\[7\] ) \* 1;      // 16^0
        iTmp += ConvertHEXASC( strRet\[6\] ) \* 16;     // 16^1
        iTmp += ConvertHEXASC( strRet\[5\] ) \* 256;    // 16^2
        iTmp += ConvertHEXASC( strRet\[4\] ) \* 4096;   // 16^3
        

        Now imagine a similar sequence of code used a few dozen times with strings of varying lengths and positions. :omg: Horror 4 : There were sixteen buttons used to select a property for the equipment and, naturally, there were sixteen different functions made to handle the clicks of the buttons. ON_COMMAND_RANGE anyone ? :wtf: The word horror barely scratches the surface for these and the rest of the things I saw there. It was staggering. Simply staggering.

        G Offline
        G Offline
        Graham Bradshaw
        wrote on last edited by
        #3

        There were sixteen buttons used to select a property for the equipment and, naturally, there were sixteen different functions made to handle the clicks of the buttons. ON_COMMAND_RANGE anyone ? And when you add another button, and the seventeenth ID is already used for something else, you have a whole heap of work to do.

        M R 2 Replies Last reply
        0
        • G Graham Bradshaw

          There were sixteen buttons used to select a property for the equipment and, naturally, there were sixteen different functions made to handle the clicks of the buttons. ON_COMMAND_RANGE anyone ? And when you add another button, and the seventeenth ID is already used for something else, you have a whole heap of work to do.

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

          Graham Bradshaw wrote:

          And when you add another button, and the seventeenth ID is already used for something else, you have a whole heap of work to do.

          There's no problem pointing multiple ON_COMMAND_RANGE macros to the same function.

          "Multithreading is just one damn thing after, before, or simultaneous with another." - Andrei Alexandrescu

          1 Reply Last reply
          0
          • G Graham Bradshaw

            There were sixteen buttons used to select a property for the equipment and, naturally, there were sixteen different functions made to handle the clicks of the buttons. ON_COMMAND_RANGE anyone ? And when you add another button, and the seventeenth ID is already used for something else, you have a whole heap of work to do.

            R Offline
            R Offline
            Rick York
            wrote on last edited by
            #5

            I do not consider renumbering the values in Resource.h to be a whole heap of work. Besides, I always leave gaps around arrays of control identifiers just in case I have to add more so this is very rarely an issue for me and when it arises it is easy to deal with.

            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