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 8227995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:19:15+00:00 2026-06-07T16:19:15+00:00

Sometimes there’s a fine line between being safe and running scared. Does this code

  • 0

Sometimes there’s a fine line between being safe and running scared.

Does this code cross the line into scaredy-cat zone?

DuckbillPlatypusForm dbpf = null;
if (radioButtonUseExistingPlatypus.Checked) {
    dbpf = new DuckbillPlatypusForm(DuckbillSetupUtils.DuckbillPlatypusState.Readonly, funnyMammalIDs);
} else if (radioButtonCreateNewFromExistingPlatypus.Checked) {
    dbpf = new DuckbillPlatypusForm(DuckbillSetupUtils.DuckbillPlatypusState.Template, funnyMammalIDs);
} else if (radioButtonCreateNewPlatypus.Checked) {
    dbpf = new DuckbillPlatypusForm(DuckbillSetupUtils.DuckbillPlatypusState.StartNew, funnyMammalIDs);
}
if (null != dbpf)
{
    dbpf.Show();
}

After all, there are only three radio buttons, and one is checked at design time, so dbpf can never be null, right? Unless somehow all of the radio buttons become unchecked at design-time, or I add another radio button without updating this code, and that one gets selected, but at what point do I just “bite the bullet” and accept suchlike risks?

  • 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-06-07T16:19:17+00:00Added an answer on June 7, 2026 at 4:19 pm

    Checking for null is good in my opinion, because there is a chance that another radio button will be added in future. Maybe from another developer of your team (not yourself), and perhaps it’s quite some time in the future.

    Maybe it would be even better to handle it as an exception, if the variable is null, because that would certainly be an error in the code, and should be fixed.

    Edit:

    If you rearrange your code a little bit, the exception thing would become very natural. Just separate the reading from the GUI.

    function DuckbillSetupUtils.DuckbillPlatypusState StateFromGui()
    {
      if (radioButtonUseExistingPlatypus.Checked)
        return DuckbillSetupUtils.DuckbillPlatypusState.Readonly;
      if (radioButtonCreateNewFromExistingPlatypus.Checked)
        return DuckbillSetupUtils.DuckbillPlatypusState.Template;
      if (radioButtonCreateNewPlatypus.Checked)
        return DuckbillSetupUtils.DuckbillPlatypusState.StartNew;
      else
        return DuckbillSetupUtils.DuckbillPlatypusState.Undefined;
    }
    
    new DuckbillPlatypusForm(StateFromGui(), funnyMammalIDs);
    

    Now if the constructor is called with State Undefined, you can throw an exception. This way, if you add another radiobutton, you have to update only this StateFromGui function, and you have a single point to test the state.

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

Sidebar

Related Questions

For example, sometimes there's an import like this: #import <Cocoa/Cocoa.h> and sometimes the import
I am inserting data into a table and sqlite3_step returns SQLITE_DONE. But sometimes there
When importing data into an MS Access Database, sometimes there are errors in the
if i have some code: variableA = self.kwarg['maybe'] now, 'maybe' is sometimes there and
I program in C++. Sometimes there are 1000 ways to do something, and depending
my Page has many hover images, sometimes there are backgrounds from div-elements or src
I have a column called post_tags where there is sometimes one tag entry and
I am writing a parser for csv-files, and sometimes I get NumberFormatException. Is there
I am trying to split an array into n parts. Sometimes these parts are
I had this doubt for sometime now, some people say that there's no such

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.