Unconventional for-loop bug
-
I can't remember the precise details but instead of the standard C for-loop style: for (int i = 0; i < size; i++) he wrote: for (int i = 0; i != size; i++) Then inside the loop he was doing some loop counter manipulation, e.g., at some point incrementing by 2 so that i == size was never true and then you got an infinite loop. He used this loop style throughout. He was a former C++ developer and I think he was just applying the STL iterator pattern for (it = coll.begin(); it != coll.end(); ++it) but inappropriately to values. I did find out subsequently that he was an STL user (as I'd suspected prior to this). (BTW, the code quality as a whole was appaliing.)
Kevin
-
I can't remember the precise details but instead of the standard C for-loop style: for (int i = 0; i < size; i++) he wrote: for (int i = 0; i != size; i++) Then inside the loop he was doing some loop counter manipulation, e.g., at some point incrementing by 2 so that i == size was never true and then you got an infinite loop. He used this loop style throughout. He was a former C++ developer and I think he was just applying the STL iterator pattern for (it = coll.begin(); it != coll.end(); ++it) but inappropriately to values. I did find out subsequently that he was an STL user (as I'd suspected prior to this). (BTW, the code quality as a whole was appaliing.)
Kevin
Kevin McFarlane wrote:
I did find out subsequently that he was an STL user (as I'd suspected prior to this).
Apparently not a very good one since "pure" STL users rarely write their own loops. ;P
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
I can't remember the precise details but instead of the standard C for-loop style: for (int i = 0; i < size; i++) he wrote: for (int i = 0; i != size; i++) Then inside the loop he was doing some loop counter manipulation, e.g., at some point incrementing by 2 so that i == size was never true and then you got an infinite loop. He used this loop style throughout. He was a former C++ developer and I think he was just applying the STL iterator pattern for (it = coll.begin(); it != coll.end(); ++it) but inappropriately to values. I did find out subsequently that he was an STL user (as I'd suspected prior to this). (BTW, the code quality as a whole was appaliing.)
Kevin
Kevin McFarlane wrote:
Then inside the loop he was doing some loop counter manipulation,
Ack. If you ever need to change the loop counter, you shouldn't be using a
for
loop. Use awhile
loop instead. It's much more intuitive. When I see afor
loop, I expect that the counter is only ever incremented on the line of thefor
keyword. Yes, I realise it wasn't you ;)Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Kevin McFarlane wrote:
I did find out subsequently that he was an STL user (as I'd suspected prior to this).
Apparently not a very good one since "pure" STL users rarely write their own loops. ;P
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
Zac Howland wrote:
STL users rarely write their own loops.
You mean they use for_each and so on? But I suspect most people learn STL initially by going through all the looping stuff. Better than avoiding it completely as many do. Algorithms and function objects I found mysterious for quite some time.
Kevin
-
Kevin McFarlane wrote:
Then inside the loop he was doing some loop counter manipulation,
Ack. If you ever need to change the loop counter, you shouldn't be using a
for
loop. Use awhile
loop instead. It's much more intuitive. When I see afor
loop, I expect that the counter is only ever incremented on the line of thefor
keyword. Yes, I realise it wasn't you ;)Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
I fully agree.
Kevin
-
Zac Howland wrote:
STL users rarely write their own loops.
You mean they use for_each and so on? But I suspect most people learn STL initially by going through all the looping stuff. Better than avoiding it completely as many do. Algorithms and function objects I found mysterious for quite some time.
Kevin
Kevin McFarlane wrote:
You mean they use for_each and so on? But I suspect most people learn STL initially by going through all the looping stuff. Better than avoiding it completely as many do. Algorithms and function objects I found mysterious for quite some time.
I was the same way. I treated vectors like normal c-style arrays. It wasn't until my data structures and algorithms class that I learned otherwise. After the first program in that class, we were no longer allowed to write our own loops. It definitely made you think about your design a little more by doing that.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac