POLL: Programming style - i++ vs. ++i
-
In terms of compiler optimization intelligence, I think we've finally surpassed the smarts of the VAX FORTRAN compiler of the late 80's. A human being could not write code that was more efficient than what that compiler generated.
Software Zen:
delete this;
-
I rarely use ++i because then I would have to take a few seconds to think on which order things are executed... John
I use
foreach
. :) Jonathan de Halleux - My Blog -
I wish there was a neither option. I try to avoid both and use i += 1. Two reasons : I wrote a scripting engine and I saw little reason for the ++ and -- operators and did not include them. This got me into the habit of using the += and -= operators which I did include. Second reason - if, for some odd reason, the incrementer needs to change to a 2 it is easier. Actually, a macro or "const int" value for the incrementer is a better way to go which I prefer to use along with the += and -= operators. Bottom line - I prefer the += method to be as consistent as possible but that's just me. __________________________________________ a two cent stamp short of going postal.
Rick York wrote: I saw little reason for the ++ and -- operators and did not include them You code in C
**++**
and do not see the need for the ++ operator? :omg::wtf: Yes, even I am blogging now! -
After a batch of interviews, the second most notable thing is that where both
++i
andi++
are possible, all candidates usedi++
Having optimizied for older compilers I automatically opt for the "simpler" concept of ++i except where I explicitely need the postfix increment. (I now that it makes no difference to today's compilers, but it might still save some microseconds when compiling :rolleyes: ) so - Vote 5 if it'sfor(int i=0; i<n; ++i)
, and Vote 1 if it'sfor(int i=0; i<n; i++)
for you. if the "programming" in the title triggers a pawlowian in you, please vote 3
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen++i is safe there but a bad habit in other places so I stick with i++. Elaine :rose: The tigress is here :-D
-
I use
foreach
. :) Jonathan de Halleux - My Blog -
++i is safe there but a bad habit in other places so I stick with i++. Elaine :rose: The tigress is here :-D
-
++i, for sure. Although a compiler may optimise, it's in theory more efficient, and never less so. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
After a batch of interviews, the second most notable thing is that where both
++i
andi++
are possible, all candidates usedi++
Having optimizied for older compilers I automatically opt for the "simpler" concept of ++i except where I explicitely need the postfix increment. (I now that it makes no difference to today's compilers, but it might still save some microseconds when compiling :rolleyes: ) so - Vote 5 if it'sfor(int i=0; i<n; ++i)
, and Vote 1 if it'sfor(int i=0; i<n; i++)
for you. if the "programming" in the title triggers a pawlowian in you, please vote 3
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen -
After a batch of interviews, the second most notable thing is that where both
++i
andi++
are possible, all candidates usedi++
Having optimizied for older compilers I automatically opt for the "simpler" concept of ++i except where I explicitely need the postfix increment. (I now that it makes no difference to today's compilers, but it might still save some microseconds when compiling :rolleyes: ) so - Vote 5 if it'sfor(int i=0; i<n; ++i)
, and Vote 1 if it'sfor(int i=0; i<n; i++)
for you. if the "programming" in the title triggers a pawlowian in you, please vote 3
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygenpeterchen wrote: please vote 3 Won't that skew the results? I thought different levels of members got different vote weights. :~ FWIW I'm an i++ guy.
David Wulff The Royal Woofle Museum
Putting the laughter back into slaughter
-
After a batch of interviews, the second most notable thing is that where both
++i
andi++
are possible, all candidates usedi++
Having optimizied for older compilers I automatically opt for the "simpler" concept of ++i except where I explicitely need the postfix increment. (I now that it makes no difference to today's compilers, but it might still save some microseconds when compiling :rolleyes: ) so - Vote 5 if it'sfor(int i=0; i<n; ++i)
, and Vote 1 if it'sfor(int i=0; i<n; i++)
for you. if the "programming" in the title triggers a pawlowian in you, please vote 3
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygenStrange for incrementing integers in for statements I use i++ For incrementing itterators I use ++it. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fuity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain) -
Memories... (my Mass license plate is VAX-VMS) :cool: Spent 8 very happy years @ Digital (when it was still Digital). /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
Indeed. I used to write entire applications in DCL :-O.
Software Zen:
delete this;
-
Indeed. I used to write entire applications in DCL :-O.
Software Zen:
delete this;
Oh yeah! Remember the DEC Professional? They were kind enough to publish several of my DCL hacks. I recall (with awe) when DCL released with VMS 3.1 first offered the
END IF
clause. What power! :omg: /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
Rick York wrote: I saw little reason for the ++ and -- operators and did not include them You code in C
**++**
and do not see the need for the ++ operator? :omg::wtf: Yes, even I am blogging now! -
exactly my thought - dunno why you were voted down...
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygenI am ALWAYS voted down. Come to the soapbox if you want to find out why :P Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder