Thursday, March 24, 2005

The logically challenged

I actually had to debug some code today that I'm not sure ever worked. It couldn't have. The creator of said code is very, very logically challenged.

What the code does is create repeat meeting room reservations. Now, that sounds simple enough. Only... Well, it did everything ass backwards. Near as I can figure anyway. It would create the first room reservation, increment the date, create the next room reservation document, then increment the date again and go check to make sure the room was available for the date. The problem.... the room was never checked for the second repeating meeting. So, I moved some code around and I discovered the second flaw with this logic....

Once the room reservation is created, it's added to the view that we're looping through to check for conflicts. So...... because the reservation is created BEFORE the date/time/room is checked when we loop through the view (similar to a db table), there's always going to be a reservation previously created for that date/time/room. The one we've just created.

So now I understand why the code incremented the date before checking for the next room... I just don't understand what genius wrote the code that allowed a room to be booked without actually checking the availability of the room. I'm also a bit surprised this didn't bite us all in the butt ages ago.

But, code fixed now. It'll register conflicts properly. I am a bit concerned that room/time conflicts can still happen as the room isn't being booked until after we check availability. So should two people want the same room and create their reservations at the same time.... But this system is being replaced in less than a month with a much more reliable system and theoretically the rooms could be, and often were, double booked before this by people creating their reservations at virtually the same time. So really, it's a known issue and the app is being replaced to fix that problem. My code isn't breaking it any more than it already was. It's either that or completely rewrite the code already written to fix the many other flaws in there that caused the flawed code I got to fix.

Yes, I really can rationalize almost anything...


Post a Comment

Subscribe to Post Comments [Atom]

<< Home