This is the fifth article in an ongoing series on Clarion embed points and how almost all Clarion developers use them in the wrong way. If you haven't read the first article in the series, then you might find that statement offensive. You might be thinking, "What does Harms know anyway? I'm a professional developer. I know how to write embed code."
...
In Figure 3 I've added a new detail line, and I've selected an Aster, quantity two2. I've pressed the Recalculate Values button. You , and you can see that the values all appear to be correct.
...
The important thing about business logic is that you should be able to use it without having to know exactly how it works. That may sound a bit counterintutive counter intuitive - after all, if it's your own code, shouldn't you know how it works? If you wrote it, yes, you should. But we all use black box code all the time. How many Clarion devs really know what's going on in Windows when a mouse is moved or a button clicked? How about the file driver system? Or even ABC? We don't need to know how these things all work; we just need to know how to use them.
...
Here's how you might declare a black box procedure to replace the CalcValues
routine:
...
And here's how you could declare a similar black box class to replace the CalcValues
routine:
InvoiceDetail Class Init Procedureprocedure(*decimal price,| long quantity,| *decimal discountRate, | *decimal taxRate) GetTotalCost procedure(*decimal totalCost) GetTaxAmount procedure(*decimal taxAmount) GetDiscountAmount procedure(*decimal discountAmount) GetSavings procedure(*decimal savings) End
...
It's also easier to extend the InvoiceDetail
class without breaking existing functionality. As written, the CalcValues
routine calculates total cost including taxes but not extended price excluding taxes. Adding a method to get the extended price would have zero effect on code already using the class, whereas with the procedural solution you'd have to make the additonal additional parameter ommitableomittable.
In this very limited set of calculations and results, the procedural approach is already starting to show some strain. What happens when things get really interesting, as when you need to start tracking multiple taxes instead of a single tax?
...