News for hackers. Stuff that matters.
Re:Signs You're a Crappy Programmer (and don't know it) by akkartik on Friday November 23, 2007 @09:21PM (#83109)
One very useful idiom:

while(readLine()) { process lines... }

where readLine() encapsulates the repetition and returns eof as well.

Re:Signs You're a Crappy Programmer (and don't know it) by mwerty on Saturday November 24, 2007 @07:36AM (#83175)
where is the line (to be processed) stored?
Re:Signs You're a Crappy Programmer (and don't know it) by akkartik on Monday November 26, 2007 @02:03PM (#83651)
In my comment I assumed it's a line in a file and that the termination condition is eof, but you can generalize to any aggregate of items. I'm just combining the test with the increment step so we can use a simple while loop without having to peel the 'first increment' step out of the loop. If that makes any sense :)
Re:Signs You're a Crappy Programmer (and don't know it) by mwerty on Monday November 26, 2007 @07:42PM (#83768)
Thanks.

I was trying to point out that the idiom becomes while(line=readline()) which I'd rather avoid since = and == often get confused in a conditional.

It would normally be silly to get into this level of detail but I use this so often.

Re:Signs You're a Crappy Programmer (and don't know it) by akkartik on Tuesday November 27, 2007 @12:19PM (#83960)
Oh, good point. I am tolerant of globals :). Also of assignment instead of equality in conditionals (with an extra layer of parens to flag their unconventional nature). I've also used class methods where the implicit variable is in this.