> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# 5 Ways to Reduce Logic Errors Using Automated Double-Checks
- URL: https://nolongerset.com/4-ways-to-reduce-logic-errors-using-automated-double-checks/
- Published: 2021-10-02T02:02:35.000Z
- Updated: 2026-05-08T13:02:05.000Z
- Description: Identify the critical functions in your application. Then, apply one or more of these techniques to ensure that if they break, someone will notice.
- Author: Mike Wolfe
- Tags: Defensive Programming, Bug Types, #Import 2026-05-20 02:59

The best way to reduce logic errors is to [perform critical calculations two different ways](https://nolongerset.com/reduce-logic-errors-in-critical-code/).

By definition, this involves twice as much work as only solving the problem one way. The benefit, though, is that [errors in logic](https://nolongerset.com/logic-errors/) become apparent before they can [grow too large](https://nolongerset.com/the-software-reliability-paradox/). I learned how devastating uncaught logic errors can be the hard way with my [$86,000 mistake](https://nolongerset.com/the-curse-of-reliable-software/).

Let's look at some practical ways that you can incorporate automated double-checks into your applications:

- Test-driven development
- Different algorithms
- Third-party code
- Multiple programming languages
- Data validity checks

## Types of Double Checks

### Test-Driven Development

Also known as TDD, this approach to development forces you to **write tests to verify the correctness of your routines *before* you write the actual routines**. 

Entire books have been written on the topic of TDD. A simple web search can send you down rabbit holes for days. Before wandering through the woods investigating details, though, it helps to take a bird's-eye view of the whole forest.

Here's the high-level overview:

1. Write tests and confirm they fail
2. Write code until all the tests pass

### Multiple Functions Using Different Algorithms

With this approach, you create two or more functions that take the same inputs and produce the same outputs. The difference between the functions lies with the implementation details. 

For example, if your critical logic involves a sorting routine, you could use a bubble sort in one case and a quick sort in the other. You would then compare the results of the two functions to ensure they always matched. If the outcomes don't match, you raise a runtime error so that you can deal with it.

Remember, a big part of creating easy-to-maintain code involves finding ways to promote errors from the bottom of [the following list](https://nolongerset.com/some-bugs-are-better-than-others/) to the top:

1. Syntax errors
2. Compile errors
3. Misunderstood requirements (before you start writing code)
4. Automated test errors (i.e., failing tests)
5. Runtime errors
6. Misunderstood requirements (after you've written the code)
7. Logic errors

**Turning a logic error into a runtime error is a big win.**

### Third-Party Code

It's not always easy to write two different algorithms to solve the same problem.

If a single developer writes both algorithms, they are more likely to make the same kind of mistake in both places than if two different developers create the algorithms. If you are a solo developer, this puts you into a bind. You have no choice but to write both algorithms.

Depending on the nature of the problem, you may be able to find an existing solution to the problem on the internet. 

Before blindly copying and pasting that solution into your program, I would challenge you to develop your own solution *before reviewing the code you found online*. Once you've done that, you can compare the results of your calculations with the code you found online.

If both pieces of code produce the same outputs, then hey, great minds think alike! If there are differences, then you can compare the two approaches and see where the problem lies (they might both be wrong!).

### Multiple programming languages

Different languages have different ways of doing things.

Python articles and tutorials regularly refer to a *Pythonic way* of designing code. This often involves thinking about a problem from a completely different angle than what you might be used to. 

**The constraints and differences among programming languages will force you to vary the approach you use to solve a problem.**

This is true among the primarily-procedural languages, like VBA, C#, Python, and JavaScript. But the differences are even more profound when you get into different [*types* of programming languages](https://en.wikipedia.org/wiki/List%5Fof%5Fprogramming%5Flanguages%5Fby%5Ftype):

- **Procedural**: VBA, C#
- **Functional**: F#, Haskell, LISP
- **Declarative**: SQL, XAML
- **Concurrent**: Go
- **Scripting**: PowerShell, AutoHotkey

### Data validity checks

[Referential integrity](https://nolongerset.com/under-100-referential-integrity/) alone is not enough to ensure that your data is valid.

Some business logic rules are difficult or impossible to enforce within your database, even with the use of CHECK CONSTRAINTs or triggers in SQL Server. For those situations, I create a series of SELECT queries that will identify invalid data.

Here are some example descriptions of data validity checks that I use in our real estate tax assessment (CAMA) software, *[Assessor2k](https://pataxsoftware.com/assessment/)*:

- *Properties with approved homestead application but no dwelling.*
- *Properties whose current ownership record does not reflect the most recent deed.*
- *Properties with approved active homestead application but applicants who are not part of current ownership.*
- *Clients with DEC'D in their name but no Date of Death listed.*

## Final Thoughts

I'm not suggesting that you write *every function* in your program twice. 

That would be insane.

Instead, apply the 80/20 rule. Identify the critical functions that would cause the greatest damage if you got them wrong. Then–and only then–use the techniques in this article to ensure that **if your critical functions break, then someone will notice*.*

---

### Referenced articles

[Reduce Logic Errors in Critical CodeSoftware Developers Can Almost Eliminate Logic Errors With This Powerful Technique![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/10/Reducing-Logic-Errors.jpg)](https://nolongerset.com/reduce-logic-errors-in-critical-code/)

[Logic ErrorsThe logic error is the most dangerous and insidious of all software errors.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/08/cars-884673_1920.jpg)](https://nolongerset.com/logic-errors/)

[The Software Reliability ParadoxThe most reliable software holds the potential to cause the greatest harm. Examples abound, from my own $86K mistake to a devastating Russian hack.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/09/monster-5017470_1920.jpg)](https://nolongerset.com/the-software-reliability-paradox/)

[The Curse of Reliable SoftwareHow does one avoid the reliability paradox? One option is to intentionally write unreliable, buggy software. There’s a better option.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2020/10/cat-963931_1920.jpg)](https://nolongerset.com/the-curse-of-reliable-software/)

[Some Bugs are Better than OthersNot all bugs are created equal. Avoid the expensive ones by making more of the ones that are easy to find and fix.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/car-2122580_1920.jpg)](https://nolongerset.com/some-bugs-are-better-than-others/)

[What is Referential Integrity?The concept of referential integrity explained in under 100 words.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/09/blockchain-2850276_1920.jpg)](https://nolongerset.com/under-100-referential-integrity/)

### External articles

[List of programming languages by type - Wikipedia![](https://en.wikipedia.org/static/apple-touch/wikipedia.png)Wikimedia Foundation, Inc.Contributors to Wikimedia projects![](https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Wiki_letter_w_cropped.svg/20px-Wiki_letter_w_cropped.svg.png)](https://en.wikipedia.org/wiki/List%5Fof%5Fprogramming%5Flanguages%5Fby%5Ftype)

[Assessment - PA Tax SoftwareThe first step in the process is tax assessment. The goal of this step is to assign a fair and equitable value to each parcel in the county relative to the value of every other parcel in the county. Our tax assessment system is designed to meet the unique needs of Pennsylvania counties. This incl…![](https://pataxsoftware.com/wp-content/uploads/2018/10/cropped-GrayHouse-192x192.png)PA Tax Software![](https://pataxsoftware.com/wp-content/uploads/2018/10/ian-keefe-449093-unsplash-2000x1200.jpg)](https://pataxsoftware.com/assessment/)

*Image by [Dorian Krauss](https://pixabay.com/users/doriankrauss-1319355/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=931256) from [Pixabay](https://pixabay.com/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=931256)*