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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:13:32+00:00 2026-05-27T05:13:32+00:00

I am using a switch statement with 13 cases, each case only has an

  • 0

I am using a switch statement with 13 cases, each case only has an one line return value.

McCabe paints this in red. Is there an easier way to write a big switch statement? It doesn’t seem complex to read, but I don’t like the default setting turning red. If other people use the same tool on my code and see red stuff they might think I’m stupid 🙂

Edit: I’m mapping different SQL-Types to my own more abstract types, therefore reducing the total amount of types.

case Types.TIME:
    return AbstractDataType.TIME;
case Types.TIMESTAMP:
    return AbstractDataType.TIME;
case Types.DATE:
    return AbstractDataType.TIME;
case Types.BIGINT:
    return AbstractDataType.NUMERIC;
case Types.DECIMAL:
    return AbstractDataType.NUMERIC;

and so on…

  • 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-27T05:13:33+00:00Added an answer on May 27, 2026 at 5:13 am

    I don’t know that much about McCabe tools. One of the things Cyclomatic complexity considers is multiple exit points.

    I like the EnumMap idea.

    If a switch is going to be used, you could have a result variable and do away with all the return statements. You can also collapse all the source values that have the same result type:

    result = null;
    
    case Types.TIME:
    case Types.DATE:
    case Types.TIMESTAMP: result = AbstractDataType.TIME
    
    // etc.
    
    return result;
    

    I think this reduces the cyclomatic complexity, regardless of what anyone thinks about it as style. And it is a different way to write the statement, though whether it is easier you should judge.

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

Sidebar

Related Questions

I have seen an example with the switch statement where each case block was
How to write following statement in c using switch statement in c int i
For as long as I can remember I have avoided using switch statement fall-through.
What's the best practice for using a switch statement vs using an if statement
What is the benefit/downside to using a switch statement vs. an if/else in C#.
I'm programming a simple text-based RPG using a switch statement for a game loop.
I was reading some switch statements and noticed one using endswitch; . Why or
I have an issue with accessing variables initialized in a switch-statement, and then using
currently i'm attempting to using a switch statement to change between time zone with
I'm creating a console app and using a switch statement to create a simple

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.