Thanks for visiting my blog - I have now moved to a new location at Nature Networks. Url: http://blogs.nature.com/fejes - Please come visit my blog there.

Wednesday, February 18, 2009

Three lines of Java code you probably don't want to write

Ah, debugging. Ironically, it's one of the programming "skills" I'm good at. In fact, I'm usually able to debug code faster than I can write it - which leads to some interesting workflows for me. Anyhow, today I managed to really mess myself up, which took several hours of rewriting code and debugging to figure out. In the end, it all came down to three lines, which I hadn't looked at carefully enough - any of the 8-10 times I went over that subroutine.

The point was to transfer all of the reads in the local buffer back into the buffer_ahead, preserving the order - they need to be at the front of the queue. The key word here was "all".
In any case, I thought I'd share it as an example of what you shouldn't do. (Does anyone else remember the Berenstain bears books? "Son, this is what you should not do, now let this be a lesson to you.")

Enjoy:
for (int r = 0; r < buffer_ahead.size(); r++) {
buffer_ahead.add(r, local_buffer.remove(0));
}

Labels:

0 Comments:

Post a Comment

<< Home