for i in range(len(my_list)): if some_condition: del my_list[i]
the range(len()) doesn’t get calculated again, so i get an IndexError for sure, the closer it gets to the end. Because in the beginning there might were 5 elements in
my_list but when I delete one and at the end I want to access
my_list I get the IndexError, because that’s now
my_list, or course. Looking at the code didn’t make it obvious, because “I knew it was correct” and “it is just too simple to contain an error”. I am not human, I am a programmer who knows!
That’s why I should be debugging again, I saw that right away, just put the watch on the
my_list and the first
del made me see the problem. That’s why I should get used to debug right away!
That made me think about my supposedly development in developing.
In 1986 or 1987 I started with Basic, I don’t think I was debugging that. There was not even a debugger for it, or was there? For my KC87 and KC 85/3 there was surely no debugger. Then, I don’t remember the year, I switched to Turbo Pascal (cooles pic). That had debugging of course. And that was just easy as changing dipers (is for me now)! F4, F5, F6 and all those key combinations for Step Over, Step Into, etc. Then in 1990 *thinking* … yes, when I was in 11th grade. I started to use C, that was strange. All those curly braces and this strange
i++ construct. Hoooh, that scared me at first. Hey man I was programming graphic stuff in Pascal, I even knew how to use the mouse and all that, and now you come to me with curly braces and that stuff. But a debugger was just standard at this time, of course! Later I was doing a lot with Delphi, Assembler, C++ and some others I guess. And I was always debugging my code. Well I remember that I didn’t when I was programming multi-threaded stuff in Delphi for my diploma, of course.
So what the heck was I doing when I accepted to stop debugging when I started programming PHP (actually already with Perl, that I was doing little before)? I think it was the fascinating world of the web, that has opened to me and made me forget about the comforts of debugging and other programming tools, that I had used until then.
But fortunately there are also debuggers for PHP now and thanks to the WingIDE there is a great debugger for Python, with all the “step into”, “step over” and watch list things, even the same key combinations as I remember them from Pascal. Great. So I will start to creep out of my black whole and debug again.