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

  • SEARCH
  • Home
  • 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 675911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:52:13+00:00 2026-05-14T00:52:13+00:00

Take some code like if (person.IsMale()) { doGuyStuff(); } else { doGirlStuff(); } Should

  • 0

Take some code like

if (person.IsMale()) {
    doGuyStuff();
} else {
    doGirlStuff();
}

Should this be written to explicitly check if person.isFemale(), and then add a new else that throws an exception? Maybe you’re checking values in an enum, or something like that. You think that no one will add new elements to the enum, but who knows? “Can never happen” sounds like famous last words.

  • 1 1 Answer
  • 1 View
  • 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-14T00:52:13+00:00Added an answer on May 14, 2026 at 12:52 am

    I think you’ve answered your own question. If you know you’re never going to see additional values:

    bool isSet = ...
    if (isSet)
    {
        return foo;
    }
    return bar;
    

    …then don’t bother. But if there’s a chance there could be more than two possible values, cover yourself. You (or the maintenance programmer two years down the road) will be grateful for it.

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

Sidebar

Related Questions

I have some code like this to take over the space bar's function: $(document).keypress(function
Why doesn't object.__init__ take *args, **kwargs as arguments? This breaks some simple code in
Let's say I have some code like this if(isset($_GET['foo'])) //do something if(isset($_GET['bar'])) //do something
Currently I have some code like this: OntologyGenerator generator = new OntologyGenerator(); generator.AddOntologyHeader(Testing); generator.AddClassDeclaration(owlBuilder);
I have some ruby code like this: result1 = function_1(params) result2 = function_2(params) result3
I have some Java code like int userid = take user input; And then
We have some code that looks like this: class Serializer { public: template<class Type>
I'm writing some code that will take a screenshot of another application, given its'
Does anyone have some code that will take a TimeZoneInfo field from .NET and
dear all, i'll take some data from the database. and join two tables.the code

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.