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. General Programming
  3. C / C++ / MFC
  4. Complex code in conditionals

Complex code in conditionals

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiondiscussion
8 Posts 4 Posters 0 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
    charlieg
    wrote on last edited by
    #1

    I need opinions on code like this: "if ((++(m_pLF->m_iLogCnt)) >= MSG_QUEUE_FILE_SIZE)" maybe it's just me and my past - I was taught never to depend on order of operations. This is handled with the parenthesis , but really, should it be that hard to analyze an IF statement?

    Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

    CPalliniC L S 3 Replies Last reply
    0
    • C charlieg

      I need opinions on code like this: "if ((++(m_pLF->m_iLogCnt)) >= MSG_QUEUE_FILE_SIZE)" maybe it's just me and my past - I was taught never to depend on order of operations. This is handled with the parenthesis , but really, should it be that hard to analyze an IF statement?

      Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

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

      That's not terribly complex, but did you really need it that way?

      In testa che avete, signor di Ceprano?

      C 1 Reply Last reply
      0
      • C charlieg

        I need opinions on code like this: "if ((++(m_pLF->m_iLogCnt)) >= MSG_QUEUE_FILE_SIZE)" maybe it's just me and my past - I was taught never to depend on order of operations. This is handled with the parenthesis , but really, should it be that hard to analyze an IF statement?

        Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

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

        Obfuscation is the best way to annoy those who have to maintain your code.

        C 1 Reply Last reply
        0
        • CPalliniC CPallini

          That's not terribly complex, but did you really need it that way?

          C Offline
          C Offline
          charlieg
          wrote on last edited by
          #4

          No, *that* one was not terribly complex, and I also selectively edited it. :)

          Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

          1 Reply Last reply
          0
          • L Lost User

            Obfuscation is the best way to annoy those who have to maintain your code.

            C Offline
            C Offline
            charlieg
            wrote on last edited by
            #5

            You know, it's one thing to obfuscate, it's another to code in such a style as approaching enemy action. It's hard enough to write clear code. The style of code I posted just seems easy to break and difficult to debug. The debugger is going to treat that like one line of code. Caveat: I freely admit that I choose to restrict how much code I put on a line. I like using ternary or conditional operator as it can make things much cleaner, as long as you don't get silly with it.

            Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

            L 1 Reply Last reply
            0
            • C charlieg

              You know, it's one thing to obfuscate, it's another to code in such a style as approaching enemy action. It's hard enough to write clear code. The style of code I posted just seems easy to break and difficult to debug. The debugger is going to treat that like one line of code. Caveat: I freely admit that I choose to restrict how much code I put on a line. I like using ternary or conditional operator as it can make things much cleaner, as long as you don't get silly with it.

              Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

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

              Absolutely agree with you. Most of the time code like that is done by people who don't know any better (copied it from the internet), or who think they are so damn clever.

              C 1 Reply Last reply
              0
              • L Lost User

                Absolutely agree with you. Most of the time code like that is done by people who don't know any better (copied it from the internet), or who think they are so damn clever.

                C Offline
                C Offline
                charlieg
                wrote on last edited by
                #7

                Well, I know who wrote the code - I'll go with clever. Bright individual, I just wanted to make sure it wasn't just me. :)

                Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

                1 Reply Last reply
                0
                • C charlieg

                  I need opinions on code like this: "if ((++(m_pLF->m_iLogCnt)) >= MSG_QUEUE_FILE_SIZE)" maybe it's just me and my past - I was taught never to depend on order of operations. This is handled with the parenthesis , but really, should it be that hard to analyze an IF statement?

                  Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

                  S Offline
                  S Offline
                  Stefan_Lang
                  wrote on last edited by
                  #8

                  This is not too complex, but at the limit where I would consider breaking it up into multiple statements. That said, if that were a while condition, I might be more inclined to leave it like that, because (a) the increment might be considered part of the loop iteration, and (b) moving part of the condition might require more than one additional line (e. g. once before the start of the loop and once inside). Apart from that, I am more bothered with the naming ;P

                  GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                  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