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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:56:46+00:00 2026-06-16T01:56:46+00:00

This discussion is about a name of default value: C#: Should the default value

  • 0

This discussion is about a name of default value:
C#: Should the default value of an enum be None or Unknown?

However, large amount of people I spoken with recently considered default enum values harmful, unnecessary and potentially leading to a bad practice.

As an example consider the following:

enum eJobStates
{
    JOB_STATE_INITIALISING,
    JOB_STATE_PROCESSING,
    JOB_STATE_DONE
};

It would not make sense for a job to be in say, JOB_STATE_UNKNOWN, but you can imagine that any structure that might be used for monitoring of said jobs could use such value.

Are there any best practices / rules of thumb concerning creating a default value when defining an enum? Should they be avoided at all cost whenever possible?

  • 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-16T01:56:47+00:00Added an answer on June 16, 2026 at 1:56 am

    An invalid default value is basically a variant in your design. The object isn’t valid when it’s created. You should avoid that when it’s reasonable. By no means should you avoid it “at all costs.”

    Some problems require you to start in a variant state. In that case, you have to reason about that invalid value mentally. If you avoid naming it you are actively making your code less expressive. Think about it in terms of communication between you and the person that will have to maintain the code later.

    Dealing with it downwind is annoying. You start in a variant state, but by the time it’s relevant you hope that it is no longer variant. The strategy I prefer is allow users to ignore the variant state and just throw when I’ve made a mistake.

    namespace FooType {
      enum EnumValue {
        INVALID = 0
        ,valid
      };
    }
    
    struct Foo {
      Foo() : val(FooType::INVALID) {}
      FooType::EnumValue get() const {
        if (val == FooType::INVALID)
          throw std::logic_error("variant Foo state");
        return val;
      }
      FooType::EnumValue val;
    };
    

    This frees your users from having to reason about your variance, which is worth fighting for.

    If you can’t get away with that, I usually prefer to degrade to safe and unsafe interfaces.

    struct Foo {
      Foo() : val(FooType::INVALID) {}
      bool get(FooType::EnumValue& val_) const {
        if (val == FooType::INVALID)
          return false;
        val_ = val;
        return true;
      }
      FooType::EnumValue get() const {
        FooType::EnumValue val_;
        if (!get(val_))
          throw std::logic_error("variant Foo state");
        return val_;
      }
      FooType::EnumValue get_or_default(FooType::EnumValue def) const {
        FooType::EnumValue val_;
        if (!get(val_))
          return def;
        return val_;
      }
      FooType::EnumValue val;
    };
    

    These sorts of interfaces are good for things like databases, where null values may be expected.

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

Sidebar

Related Questions

If there is already a discussion about this somewhere, I'll take a link as
We were having this discussion wiht my colleagues about Inner assignments such as: return
Sometimes I heard people discussing about the start-up time for Java. It seems this
For ease of discussion, consider this basic table (Test) in Access... ID division name
In this discussion , a solution is suggested by referral to the name of
I got interested in this discussion about AST construction and evaluation in various languages
Recently I had this discussion with some other developers about how too many columns
Following this discussion , I've encountered a bad access issue; A loop has several
I was recently reading this discussion at SO where somebody commented that not all
We're having this discussion here. Which is better and why? 1) a php file

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.