3 ms·
Lesson I took away: The ++ operator should be deprecated except when it's the only operation on that line.
by SilasX 13y ago
Lesson I took away:
The ++ operator should be deprecated except when it's the only operation on that line.
- deletes 13y agoI think users of for/while loops will disagree. Don't forget that =, += , ... can all be abused in the same way.
- SilasX 13y ago(int i=0;i<10;i++) would count as three lines for purposes of that rule, and the i++ as one. I could have been more precise, but I thought it would be understood. The point is, to be on the safe side, don't use ++/-- in any line (in the sense of ;{}-delimited statement) that is also doing something else. >Don't forget that =, += , ... can all be abused in the same way. I didn't, and people should use the same safeguards around them, i.e. don't mix them within lines that do other things, "cleverness" or "C golf" be damned.
- bookface 13y agoI like using it when I'm filling an array with an indeterminate number of elements. I've used this pattern a few times: foo foos[255]; int ct = 0; if (<condition for adding first element>) foos[ct++] = foo1; if (<condition for adding second element>) foos[ct++] = foo2; ... for (int i = 0; i < ct; i++) { /* do something with foos[i] */ } IMHO, this is more concise and readable than separating the increment and assignment into two lines.
- deleted 13y ago[deleted]