I've been working on one task for last several days. In a product I work there is feature that looks like Excel - template editor. User is able to put a data to sheets and do some simple calculation with formulas (SUM, MUL etc.). This functionality has been created far ago and worked fine. But recently we've changed our engine and now we support not only "plain" data structure, but expanded one - when user is able to say - "this column or row is expanded with such data". Data size is dynamic and could be predicted while template edition and SUM function have to take into account that data is expanded.
So, I've created a number of test cases that cover new functionality and implemented simple mechanism that process formula like SUM(A1:B2) and adjust start and finish indexes according to size of expansion. At the beginning that
AdjustIndexes function were small and easy to read, it just perform simple calculation based on current row/current column, original indexes places and some information from expanded data.
But after a demo we've found some bugs: if several expansions present in template - it fails. If not expanded data comes after expanded it fails and some more..
I've extended tests cases with all found issues and start to attack problem. I start to adjust
AdjustIndexes to work with new cases. And after a while I've completed it, but this function started to look scary - a lot of nested if-else cases, calculation of indexes, += operations etc. OK, I thought.. it could be refactored later, so I did a checkin. My happiness was not long, because while developers tests I just found another bug. OK, usual stuff - test and fix. Let's go.
Meanwhile I've already spent about 6 hours on that. At stand-up I said - "it seems to be alright, only one case is failing now, I'm finishing up and commit". But I was wrong. As I changed the function to work with new case, new case became green but existing ones became red.. I fell stress that task originally estimated for 1 day is now 1.5 and supposed to be about 2 days. I wanted to do quickly, so started to play a game - "Change something, re-run the tests if GREEN - you win!" (such approach actually works some time as soon as you got good test cases and double check the results). Already created function became more scary and what is worse - it does not satisfied all tests. I lost the control of it and only one I understand - "I do not now understand this function works now.. It does something wrong and I have to go with another idea to solve the problem".
It was about 10 hours spend on that. I started to lose the game, but just didn't want to give up. I need another idea, I need another approach.. I need additional data structures that would help to map original table indexes to expanded ones, I need to change the engine to fill those mapping, I need to change
AdjustIndexes function to take mapping into account. I felt a little tired and stressed but proceed with coding like crazy.
14 hours passes, late evening, and I was finishing up my
Mapping mechanism, while I was contacted by my teammate Carsten - "How is it going with SUM?". I've explained my issues, my approach and my status, but basically it was like - "It is not yet done". But he said that it seems like I'm doing something wrong and proposed another algorithm of doing this adjustment, with no other additional data structures. I probably was to tired to understand everything there, so he just said "Wait for 30 minutes, I'll do some code and show to?". I've been shocked, something I worked for 14 already he want to do in 0.5 hour? OK.
He sent his first solution. Hopefully it was only one function to change I could easily integrated and re-run all test cases I had so far. Most of them were failed at first try. We started a pair session and after several run/fix/test sessions it started to work! All tests are green! It works in application.. Function is quite small and easy to read.
Yeahh.. that was such great work (respect to Carsten) and so such shame on me. 15 hours.. vs 40 minutes.. 30 lines of code vs. 300.. one point of integration vs. many. I've been defeated.
When I finished it up and went a street to walk with dog, I've tried to find at lest something positive in all this situation. And you know what? I can up with one another feature to trackyt.net.
If you have a task in progress and you spend 12 (8, 6 or even 4) hours, task is became red and interacts with user:
- Take a rest, re-think
- Ask for help
That would prevent my situation somehow. It will try to say to you "Man, you probably stucked with that, ask some one to take a look".. This seems to be obvious, but if you are in hurry you are not just doing that hoping to handle everything by yourself. This is not good. I was happy about such idea and lesson learned, so back to home with good mood already :).
Have you been to such situation, do you think it's valuable if you have some stopwatch and notifier that would push you shoulder and say "Stop now ask for help!" ?