Complex code in conditionals
-
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
-
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
-
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
-
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
-
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
-
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
-
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.
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
-
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
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 ;PGOTOs 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)