Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
Get a devDuck
Rubber duck debugging has never been so cute! Get your favorite coding language devDuckBuy Now
Search - "the woes of maintenance"
In my first summer at my internship I was fixing up a PHP script that a previous developer wrote... It collected our customer's emails and sent them to MailChimp for marketing.
The SQL query to get the emails was pretty standard, but what he did next was not.
There were for loops nested 3 deep. The outer loop's counter was i. The inner was ii. And the deepest was iii. That alone made it hard to read, but for a couple years some iii's and ii's were mixed up when getting values for arrays. So it was even harder to tell what it was supposed to do.
The inner loop also started at i-20. This was so he could look through and see if an email was already included from that query and skip it. But he didn't check the bounds, so the first 20 times through the outer loop, the inner loop would throw `undefined index -20` errors.
In order to fix all this I did an order by on the query, and kept a last email variable that I used for comparison. Pretty basic. This also lowered it to just one loop.
I talk about it on a regular basis with my coworkers and we all laugh about it. I also bring it up when upper management thinks they can code, because that ex developer is now an executive.