Sitting here writing some code on a parser, so while writing a counter I needed to write something like
if ... {
...
some_list.clear();
counter++;
continue;
}
But, do you think writing it this sort of way is nicer,
...
++ counter; // With a space after operator
continue;
}
The thought was, maybe if you have some code around this, it'll stand out more... I don't know. What do you think?
Suppose I should also get some design practises book along with the other two books I am getting next week.
view the rest of the comments →
[–] badkangaroo ago
i often see in a for loop (;;++i) or (;;i++) someone suggesting that ++i was better for some reason, any ideas why?
[–] skruf [S] 0 points 1 point 1 point (+1|-0) ago (edited ago)
Even though modern compilers optimize for either of these uses, I'm sure, the idea was that when post-incrementing (i++), 'i' here will return the value and then increment it, which apparently takes more time than pre-increment (++i) where you would increment and then get the new value.
Actually, I'm in the habit of pre-increment in the for-loops, I think it's more of an uncontrolled obsession than anything else...
[–] WhiteMakesRight 1 point -1 points 0 points (+0|-1) ago (edited ago)
It makes zero difference which of the two you use as the third expression in a
forloop. Whenever you see someone prescribing rules without explaining their reasoning, it's a good idea to disregard everything they say.