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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:10:25+00:00 2026-05-22T18:10:25+00:00

int scalar = creature is SpecialCreature ? (creature.IsAwesome ? 700 : 500) : (creature

  • 0
        int scalar = creature is SpecialCreature ? (creature.IsAwesome ? 700 : 500) : (creature is NotSoNormalCreature ? 
            (creature.IsAwesome ? (creature is IGreatCreature ? 450 : 280) : 240) : 
            (creature.IsAwesome ? (creature is IGreatCreature ? 300 : 200) : 160));

how should I write that code to make it more readable?

I thought of just building the ifs, but then I thought how about making some kind of “ConditionFactory”? Would that make any sense, or is it just too intricate for such a simple task?

int scalar;

if (creature is SpecialCreature)
{
    scalar = creature.IsAwesome ? 700 : 500;
}
else if (creature is NotSoNormalCreature)
{
    if (creature.IsAwesome)
    {
        scalar = creature is IGreatCreature ? 450 : 280;
    }
    else
    {
        scalar = 240;
    }
}
else
{
    if (creature.IsAwesome)
    {
        scalar = creature is IGreatCreature ? 300 : 200;
    }
    else
    {
        scalar = 160;
    }
}
  • 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-22T18:10:26+00:00Added an answer on May 22, 2026 at 6:10 pm

    Not sure entirely what you’re going for, but since you are using a base type inheritance chain, you might elect to do something like

    interface ICreature
    {
        bool IsAwesome { get; set; }
        int GetScalar();
    }
    
    abstract class Creature : ICreature
    {
        public bool IsAwesome { get; set; }
        public virtual int GetScalar()
        {
            return 160;
        }
    }
    
    class SpecialCreature : Creature
    {
        public override int GetScalar()
        {
            return this.IsAwesome ? 700 : 500;
        }
    }
    
    class NotSoNormalCreature : Creature
    {
        public override int GetScalar()
        {
            return this.IsAwesome ? 450 : 280;
        }
    }
    
    // more ICreatures...
    

    Which would allow you to have the creature implement its own logic for determining the scalar, and your consuming code can lose the complication of caring.

    ICreature creature = GetCreatureFromSomewhere();
    int scalar = creature.GetScalar();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: Unit: UnitId int PK Title varchar UnitOption: UnitOptionId int PK
When I create a scalar INTEGER, s, and pass it to a subroutine, its
I am using a Scalar-Valued Function to find out if a user of the
I have those two classes ///////////BASE CLASS class Base{ public: Base(int = 0); ~Base();
What is the best way to do the equivalent of execute scalar in T-SQL?
I have a class, say class AddElement{ int a,b,c; } With methods to set/get
I have this domain object: case class Person ( name : String, age: Option[Int],
I have this C++ code: #include <iostream> using namespace std; struct MyItem { int
I dont mean a variable in a class but a default value for the
I have a Stack container class and I want to create instances of various

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.