... and having no automated tests.
Do you ever have those "what the $!*&# was I thinking?" moments? I had one this morning
when working on some legacy code. My guess is that it was probably written six or more years ago,
though someone touched it as late as two years ago. I guess technically it isn't legacy since it is still supported (I'm fixing it aren't I?), but you get the idea.
You see, it was noticed that an order from Portugal to be shipped to California was showing the
customer that they would be charged sales tax, but it was not charging the tax, nor was it showing on the receipt. Can you believe that in all this time, not one customer has ever had that happen?
(Me either)
So, I went to inspect the source to see what the problem was. Only it took me probably half an hour
to find the problem. Why? Because obviously it's best if you can calculate the same thing in
as many different places as possible.
And I'm not talking about something like having
tax=calculateTax(someArgs)
in one place and
taxAmount=calculateTax(someArgs)
in another because I forgot what I named the
first variable and I was too lazy to scroll up 10,000 lines to see what it was. I'm talking
"loop through the order to total it, check if the shipping state and billing state are both California, and if so apply tax calculation and add the result to the order total." In three different spots between two different files.
And the best part? As you can tell from the fact the receipts were saying one thing and the web page another, they didn't even follow the same rules. So, the first thing to do was to figure out what
the correct rule was, and then implement it in all three spots.
Just kidding ... I put the code into one spot and reused it.
Hey! Why don't you make your life easier and subscribe to the full post
or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate
wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!
Leave a comment
There are no comments for this entry yet.
Leave a comment