CodeSOD: Stocking Up

This post was originally published on this site

The Daily WTF

Sometimes, you find some code that almost works, that almost makes sense. In a way, that’s worse than just plain bad code. RenĂ© was recently going through some legacy JavaScript code for their warehouse management system.

Like any such warehousing system, there’s a problem you have to solve: sometimes, the number of units you need to pick to complete the order is larger than the stock you have available. At that point, you need to make a decision: do you hold the order until stock comes in, do you partially fill it and then follow up with a second shipment, or do you perhaps just cancel the order?

René found a line like this:

pick.qty_to_pick -= pick.qty_to_pick – stock.available

So, if I want to pick 100 units, but only have 25 in stock, I’ll decrement the qty_to_pick by 75. Which vaguely makes sense, but also is a

To read the full article click on the 'post' link at the top.