# Navigating the Waters of Decision-Making and Debugging: A Guide to Assertions and the Sunk Cost Fallacy

Kai Nguyen

Hatched by Kai Nguyen

Oct 31, 2025

4 min read

0

Navigating the Waters of Decision-Making and Debugging: A Guide to Assertions and the Sunk Cost Fallacy

In the realm of programming and decision-making, two seemingly disparate concepts emerge: Python's assert statements for debugging and the psychological phenomenon known as the sunk cost fallacy. While they belong to different domains, both highlight the importance of rational thought and intentionality in our actions—whether in code or in life decisions. This article explores how assertions can be effectively utilized in programming and how understanding the sunk cost fallacy can enhance our decision-making capabilities.

Understanding Python's Assert Statements

What Are Assertions?

At its core, an assert statement in Python serves as a debugging tool, acting as a watchdog of sorts for your code. When an assertion fails—meaning the condition specified evaluates to false—it raises an AssertionError, alerting the programmer to a potential bug. Assertions are particularly useful for setting sanity checks, which help ensure that certain conditions hold true during development.

The Purpose of Assertions

Assertions play a critical role in documenting, debugging, and testing code. They allow developers to check assumptions about their code, such as preconditions and postconditions, facilitating the identification of bugs at an early stage. By using assertions, programmers can quickly flag potential issues, ensuring that errors are caught and addressed before they escalate.

For example, a simple assertion might look like this:

assert x > 0, "x must be positive"  

If x is not greater than zero, the assertion will fail, providing an immediate indication of where the issue lies.

When Not to Use Assertions

While powerful, assertions are not a catch-all solution. They should not be relied upon for data processing or validation in production environments. Assertions are designed for use during development; when the code is deployed in a production setting, they can negatively impact performance and should be disabled. This can be accomplished by running Python with the -O or -OO command-line options, which optimize the code by removing assertions and docstrings.

Common Formats of Assertions

Assertions can take various forms, including:

  • Comparison assertions: Checking if two or more objects are equal.
  • Membership assertions: Determining if an item exists within a collection.
  • Identity assertions: Testing for object identity.
  • Type check assertions: Verifying if an object is an instance of a particular class.

By employing these formats, developers can create comprehensive checks that suit their specific needs.

The Sunk Cost Fallacy: A Psychological Insight

What is the Sunk Cost Fallacy?

The sunk cost fallacy describes our tendency to continue investing in a project or decision based on prior investments of time, effort, or money, rather than evaluating the current and future costs and benefits. In economic terms, sunk costs are expenses that cannot be recovered. Yet, many individuals and organizations fall prey to this cognitive bias, leading them to make irrational decisions.

One prominent example is the Concorde Fallacy, where governments continued to fund the Concorde aircraft project despite its unprofitability, simply because of the substantial investments already made.

The Emotional Influence on Decision-Making

The sunk cost fallacy is closely linked to commitment bias, where emotional attachment to previous investments clouds judgment. To mitigate this, it's crucial to focus on future costs and benefits rather than past commitments. By recognizing when a project is not yielding the expected results, decision-makers can make more rational choices, avoiding the trap of throwing good resources after bad.

Leveraging Technology for Better Decisions

In our increasingly complex world, technology can aid in decision-making by providing data-driven insights and reducing the emotional weight of past choices. Information technology systems can evaluate options purely based on current conditions, free from the biases that often hinder human decision-makers.

Bridging the Gap: Assertions and Rational Decision-Making

Both Python's assert statements and the concept of the sunk cost fallacy emphasize the need for clear, rational thinking—whether in programming or decision-making. Just as assertions help programmers identify and address errors early on, understanding the sunk cost fallacy can help individuals and organizations make better choices by preventing emotional biases from influencing decisions.

Actionable Advice

  1. Employ Assertions Wisely: Use assert statements during the development phase to catch errors early. Ensure that they are descriptive, so when an assertion fails, the message clearly communicates the issue.

  2. Avoid the Sunk Cost Fallacy: Regularly evaluate ongoing projects by focusing on current and future benefits rather than past investments. Create a culture where it is acceptable to abandon projects that no longer serve their intended purpose.

  3. Utilize Technology for Decision Support: Implement decision-making tools and technologies that can analyze data without emotional bias. This can help teams make more objective choices, enhancing overall productivity and project outcomes.

Conclusion

In both programming and decision-making, the principles of rational thought and intentionality are paramount. By effectively utilizing assertions, developers can maintain the integrity of their code, while recognizing and overcoming the sunk cost fallacy can empower individuals and organizations to make sound decisions. Both strategies encourage a forward-thinking mindset, ultimately leading to more successful outcomes in both coding and life.

Sources

← Back to Library

Hatch New Ideas with Glasp AI 🐣

Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)

Start Hatching 🐣