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 →
[–] RicardoBronson ago (edited ago)
They both suck because of unspecified behavior in some situations. And usually when you want it least. Like for loops using pointers. Trust me, just say "counter += 1" and you will never have to know the pain EDIT: Actually why bother trusting me, do a search: https://www.google.com/search?hl=en&q=postfix%20increment%20unspecified%20behavior
[–] WhiteMakesRight 1 point -1 points 0 points (+0|-1) ago (edited ago)
The operators have nothing to do with the unspecified behaviour you're talking about though -- they're just a succinct way to trigger it. What's actually unspecified is the order of evaluation of function arguments -- which is something you should be aware of even if you never use increment operators.
Not using increment operators at all is a typical example of "scarring on the first cut". If you're going to write software in C, rules-of-thumb will only get you so far. At some point, you have to read and understand the specification in depth.
[–] RicardoBronson ago
I take more of a "when in doubt, do it in python" approach because life is just too short to spend on specifications :) But I'm sure you're right