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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:03:01+00:00 2026-05-10T22:03:01+00:00

Why does everyone tell me writing code like this is a bad practice? if

  • 0

Why does everyone tell me writing code like this is a bad practice?

if (foo)     Bar();  //or  for(int i = 0 i < count; i++)     Bar(i); 

My biggest argument for omitting the curly braces is that it can sometimes be twice as many lines with them. For example, here is some code to paint a glow effect for a label in C#.

using (Brush br = new SolidBrush(Color.FromArgb(15, GlowColor))) {     for (int x = 0; x <= GlowAmount; x++)     {         for (int y = 0; y <= GlowAmount; y++)         {             g.DrawString(Text, this.Font, br, new Point(IconOffset + x, y));         }      }  }  //versus using (Brush br = new SolidBrush(Color.FromArgb(15, GlowColor)))     for (int x = 0; x <= GlowAmount; x++)         for (int y = 0; y <= GlowAmount; y++)             g.DrawString(Text, this.Font, br, new Point(IconOffset + x, y)); 

You can also get the added benefit of chaining usings together without having to indent a million times.

using (Graphics g = Graphics.FromImage(bmp)) {     using (Brush brush = new SolidBrush(backgroundColor))     {         using (Pen pen = new Pen(Color.FromArgb(penColor)))         {             //do lots of work         }     }  } //versus using (Graphics g = Graphics.FromImage(bmp)) using (Brush brush = new SolidBrush(backgroundColor)) using (Pen pen = new Pen(Color.FromArgb(penColor))) {     //do lots of work } 

The most common argument for curly braces revolves around maintance programming, and the problems that would ensue by inserting code between the original if statement and its intended result:

if (foo)     Bar();     Biz(); 

Questions:

  1. Is it wrong to want to use the more compact syntax which the language offers? The people that design these languages are smart, I can’t imagine they would put a feature which is always bad to use.
  2. Should we or Shouldn’t we write code so the lowest common denominator can understand and have no problems working with it?
  3. Is there another argument that I’m missing?
  • 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-10T22:03:02+00:00Added an answer on May 10, 2026 at 10:03 pm

    Actually, the only time that’s ever really bit me was when I was debugging, and commented out bar():

    if(foo)   // bar(); doSomethingElse(); 

    Other than that, I tend to use:

    if(foo) bar(); 

    Which takes care of the above case.

    EDIT Thanks for clarifying the question, I agree, we should not write code to the lowest common denominator.

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

Sidebar

Related Questions

Does everyone just use XML in the message? Are there any good alternatives to
What java GUI layout manager does everyone use? Lately, I have been using MigLayout
I'm using a DateTime in C# to display times. What date portion does everyone
Seems everyone recommends virtualenv for multiple python versions (on osx), but does it even
Hello everyone I'm trying to work with jboss messaging, does anyone knows the default
i use this code to split a data to make a list with three
I've got a few questions related to the use of MonoRail Testing Does everyone
What’s the best/standard way of merging two associative arrays in JavaScript? Does everyone just
I've seen this all over the place on stack overflow, but everyone else's solution
I'd like something like a generic, re-usable getPosition() method that will tell me 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.