𝗧𝗵𝗲 𝗪𝗼𝗿𝗸𝗲𝗱 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 𝗧𝗵𝗮𝘁 𝗗𝗶𝘀𝗮𝗴𝗿𝗲𝗲𝗱 𝗪𝗶𝘁𝗵 𝗜𝘁𝘀 𝗢𝘄𝗻 𝗖𝗮𝗹𝗰𝘂𝗹𝗮𝘁𝗼𝗿
I run a site for home improvement cost calculators.
Each page shows costs in four places:
- An interactive widget.
- A static reference table.
- Written examples in the text.
- An FAQ section.
I found a major bug. A written example said a project cost $62,300. The widget said the same project cost $56,779.
There was a $5,500 gap.
The numbers were not random. They came from different hidden assumptions. The written text assumed a new HVAC unit. The widget assumed you would use the existing system. Both were fine, but they did not talk to each other.
This is a common failure. When you store the same fact in two spots, they drift apart. You are not just duplicating content. You are duplicating data.
I fixed this with a rule I call source-first. It has two parts.
Part one: A cost only exists in one place.
I stopped typing numbers into my text and tables. Now, the calculator function is the only source. The tables and written examples pull their numbers directly from that function during the build process. If the function changes, every number on the page changes automatically. You cannot have a mismatch because the numbers are the same value.
Part two: Every number must show its origin.
Cost data is not a permanent fact. It expires. I added a small data object to every calculation. It shows:
- The scenario used.
- The source of the data.
- The date it was accessed.
- When the data should be reviewed.
This keeps the data honest. If the source data is wrong, the whole site will be wrong. But at least the site will be consistent. A user notices a contradiction immediately. That destroys trust.
The lesson is simple:
- If two places on a page show the same number, one should import it. Do not retype it.
- Use your build process to sync data. This turns a discipline problem into a technical impossibility.
- Stop hand-writing numbers that a function already calculates.
I spent a day deleting numbers instead of writing them. My codebase is smaller and it no longer lies to my users.
Source: https://dev.to/mark_b5f4ffdd8e7cd58/the-worked-example-that-disagreed-with-its-own-calculator-4cp9