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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:28:27+00:00 2026-05-10T23:28:27+00:00

I just finished watching the Google clean code video on YouTube (see link ,

  • 0

I just finished watching the Google clean code video on YouTube (see link, first article) about removing if statements from your code and using polymorphism instead.

After watching the video I had a look at some code that I was writing before watching the video and noticed some places where I could use this method, mainly places where the same kind of logic was implemented many times. So a example:

I have some code like this.

public int Number {     get     {         string returnValue;         if (this.internalTableNumber == null)              returnValue = this.RunTableInfoCommand(internalTableName,                                                     TableInfoEnum.TAB_INFO_NUM);         else              returnValue = this.RunTableInfoCommand(internalTableNumber.Value,                                                     TableInfoEnum.TAB_INFO_NUM);         return Convert.ToInt32(returnValue);     } } 

What RunTableInfoCommand does isn’t really important,but the main thing is that I have many properties with exactly the same if statments the only thing that changes is the TableInfoEnum.

I was wondering if someone could help me refactor this so that it still does the same thing but without any if statements?

  • 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. 2026-05-10T23:28:27+00:00Added an answer on May 10, 2026 at 11:28 pm

    Just a cautionary note here after seeing some of these (technically correct) reponses, just getting rid of an If statement should not be your sole aim, the aim should be to make your code extensible, maintainable and simple, if that means getting rid of an if statement, great, but it shouldn’t be an aim in an of itself.

    In the code sample you have given, and without knowing more about your app, and assuming you are not going to extend much past testing for a null value, I think an If (or perhaps even a ternary) is the more maintainable solution to be perfectly frank.

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

Sidebar

Related Questions

Just finished read this post by Greg Young, where he is talking about Microsoft
I just finished a medium sized web site and one thing I noticed about
I just finished setting up an out-of-place build system for our existing C++ code
I just finished reading this article on the advantages and disadvantages of exceptions and
I just finished transferring as much link-structure data concerning wikipedia (English) as I could.
I just finished watching an episode of Bob Martin at NDC where he said
I just finished watching Stefan Schackow's PDC 2009 session and he mentioned that he
I'm watching the 2010 Google I/O video on this topic and I have a
I just got finished watching a railscast episode #189 and the was using a
I've just finished putting together a basic flash video chat client that publishes the

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.