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

The Archive Base Latest Questions

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

I mean would it be bad practice if I want an if statement to

  • 0

I mean would it be bad practice if I want an if statement to have an else, but there is a nested if statement “in my way” so I use a blank else statement such as “else ;” or “else { }” to escape it?

ex:

if (lsvAddons.SelectedItems.Count > 0)
    foreach (ListViewItem A in lsvAddons.SelectedItems)
        if (Addons[A.Index] != null) Addons[A.Index].DoHelp();
        else { }
else Console.WriteLine(_GenericHelpString);

vs:

if (lsvAddons.SelectedItems.Count > 0)
{
    foreach (ListViewItem A in lsvAddons.SelectedItems)
        if (Addons[A.Index] != null) Addons[A.Index].DoHelp();
}
else Console.WriteLine(_GenericHelpString);

Or even:

if (lsvAddons.SelectedItems.Count > 0)
{
    foreach (ListViewItem A in lsvAddons.SelectedItems)
    {
        if (Addons[A.Index] != null) 
        { 
            Addons[A.Index].DoHelp();
        }
    }
}
else
{
    Console.WriteLine(_GenericHelpString)
}
  • 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-16T21:32:27+00:00Added an answer on May 16, 2026 at 9:32 pm

    Braces are your friend.

    You’ll be ahead of the curve if you resist the urge to omit braces. The third form is completely unambiguous, easier to read, and will help you avoid inadvertant errors. I don’t know about you, but I can understand the behavior of the third form right away .. the first two forms require more thinking and mental parsing to get right.

    Many developers try to get rid of braces and use the implicit form of if statements. Unfortunately, what do you do when you run across something like:

    if( someCondition... )
        DoSomething();
        DoAnotherThing();
    

    Did the developer simply indent incorrectly? Or was the intent to have both methods part of the same condition? It can be hard to tell after the fact … and is a leading source of defects. Here’s an even worse example:

    if( someCondition );
        DoSomething();
        DoAnotherThing();
    

    Do you notice the subtle mistake here?

    You’re much better off in the long run if you make your code unambigous and less prones to these kinds of problems.

    Often developers argue to omit braces so that their code is shorter and easier to understand. Now, there’s certainly merit to avoiding long methods (some even argue that methods should always be 1-screen long) … but I don’t think the risk introduced by this kind of brevity is generally worth the reward. Keep in mind, there are ways to restructure methods to avoid excessive nesting – and they often gain you more in readability than omitting braces do.

    My personal mantra is:

    1. Make it correct.
    2. Make it clear.
    3. Make it concise.
    4. Make it fast … in that order.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With regards to OOP, how would you describe an interface? What I mean is,
I mean 100+ MB big; such text files can push the envelope of editors.
I mean, is there a coded language with human style coding? For example: Create
I mean what the most efficient way to get information about the quantity of
We have an existing Web application and we want to migrate from a custom
I want to apologize for my bad english first. I am trying to implement
Is it considered bad practice to pair function names with classes? For example in
I would like to create a struct and use it inside an other struct
I have an application in Asp.net MVC where at some point I would like
I mean, this is Sakai , the open source project of a learning management

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.