|There's more than one way to do things|
To auto-calc or not auto-calcby jk2addict (Chaplain)
|on Jul 21, 2005 at 13:02 UTC||Need Help??|
jk2addict has asked for the wisdom of the Perl Monks concerning the following question:
That is my question. :-) This isn't a perl question more than it is a perl project question and a question about consistancy , user expectations, and staying out of the way of the user. It may very well be destine to meet Node Reaper.
In Handel there are two major sets of data: cart w/items and orders w/items. For the cart, subtotal is not a field but is instead calculated by adding the total price of all of the items. The total of each cart item is price*quantity. total is not a field and is calculated on the fly. Module consumers can not add/alter the subtotal/total values since their not fields. These were meant to same the module consumer work and seems like a normal expectance ot total/subtotal.
On the flip side, there is the order data. The subtotal field is a real field and is not calculated from the item totals. The items total field is also a real field and not calculated by price*quantity. Module consumers can edit/add/update this the subtotal/total fields at will.
This sprung from the idea that an order records should be ready and taken for their face value with no fields calculated on the fly as those calulation methods may change over time. The goal is to store the data as it was the time the order was placed and never calulated anything about that order again.
What I'm now struggling with is module consumer expectations and which way is really correct. What confusion is caused by auto-calculating subtotal/total in one place but not the other? On the flip side, what harm is generated by getting in the way of the module comsumer creating totals that may appear to be 'wrong' math wise, but not for some other business reason?
Like I said, this isn't a perl question. I'm just looking for experience from others here about when to or not to try and help the user by doing things for them vs. letting them shoot themselve in the foot.