Bit of background to explain the reasoning: I've been programming for a good while, but took a break between 2012 and 2014 for other stuff. Before that break, I would hardly ever hear about "++i", let alone hear decent explanations about it ("...isn't it... just better?" was common to hear). Now, however, I see it everywhere, and even some text editors seem to use this by default (Sublime Text comes to mind).
So I've been wondering; did "++i" become suddenly very popular as of late, or is my new work environment pro-prefix increment operators?
(another possible solution is that my old environment wasn't big on "++i" for some reason)
Note that I am definitely not asking whether this is a good thing or not; I'm well aware of how pre-increment operators work, and honestly there are enough debates about this on SO. I'm just asking if this is a local trend, or a more global one. Also this is strictly for C, not C# or Java.
return recurse(i++)
rarely does what someone expects it to.return recurse(++i)
is better in that its more likely to be what is expected.return recurse(i + 1)
would be better yet. Maybe someone got burnt with the first one and switched to their own form of yoda conditions? – Apr 07 '15 at 14:57So I've been wondering; did "++i" become suddenly very popular as of late, or is my new work environment pro-prefix increment operators?
- No? I mean, it became suddenly popular like 15 years ago from what I remember. There was a book (Effective C++? That doesn't seem right looking at a chapter list, but it was something like that) that pointed out a micro-optimization with using++x
infor
loops. – Telastyn Apr 07 '15 at 15:14for(;;)
loop. i remember learning C in the context of also programming for the Motorola MC680x0. the post-increment on pointers was nearly always free, with the post-increment addressing mode. personally, i would never use a pre-increment and seldom use a pre-decrement (only when i have created my own LIFO stack, i would use post-increment along with pre-decrement). otherwise i would never pre- anything. i just think it's bad form. – robert bristow-johnson Apr 07 '15 at 16:09