Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3235318
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:29:34+00:00 2026-05-17T17:29:34+00:00

Occasionally I’ll have a situation where I’ve written some code and, based on its

  • 0

Occasionally I’ll have a situation where I’ve written some code and, based on its logic, a certain path is impossible. For example:

activeGames = [10, 20, 30]
limit = 4

def getBestActiveGameStat():
    if not activeGames: return None
    return max(activeGames)

def bah():
    if limit == 0: return "Limit is 0"

    if len(activeGames) >= limit:
        somestat = getBestActiveGameStat()
        if somestat is None:
            print "The universe has exploded"
        #etc...

What would go in the universe exploding line? If limit is 0, then the function returns. If len(activeGames) >= limit, then there must be at least one active game, so getBestActiveGameStat() can’t return None. So, should I even check for it?

The same also happens with something like a while loop which always returns in the loop:

def hmph():
    while condition:
        if foo: return "yep"
        doStuffToMakeFooTrue()

    raise SingularityFlippedMyBitsError()

Since I “know” it’s impossible, should anything even be there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:29:35+00:00Added an answer on May 17, 2026 at 5:29 pm

    If len(activeGames) >= limit, then
    there must be at least one active
    game, so getBestActiveGameStat() can’t
    return None. So, should I even check
    for it?

    Sometimes we make mistakes. You could have a program error now — or someone could create one later.

    Those errors might result in exceptions or failed unit tests. But debugging is expensive; it’s useful to have multiple ways to detect errors.

    A quickly written assert statement can express an expected invariant to human readers. And when debugging, a failed assertion can pinpoint an error quickly.

    Sutter and Alexandrescu address this issue in “C++ Coding Standards.” Despite the title, their arguments and guidelines are are language agnostic.

    Assert liberally to document internal assumptions and invariants
    … Use assert or an equivalent liberally to document assumptions internal to a module … that must always be true and otherwise represent programming errors.

    For example, if the default case in a switch statement cannot occur, add the case with assert(false).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Occasionally I'll have some WPF C# code that I'd like to write in a
Occasionally I have to do some profiling work on Java code, and I would
Occasionally I will have some badly formed PHP code and I will get a
Occasionally I like to spend some time looking at the .NET code just to
Occasionally I am looking at some code, I search for usages of a method
We occasionally have to make schema changes to mysql or mssql based production databases.
Occasionally, I will write some code with way more parentheses than I like. if(!(new
Occasionally a TextView with dynamic content will show a price. For example, as part
Occasionally I have a problem when I attempt to update a web reference in
Occasionally , we have to write methods that receive many many arguments , for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.