A single line after if shouldn’t require {braces}

I saw many C# style guidelines (or even enterprise standards) requiring that the code statements within of if (or else, or else if) clause should always require braces ({, }), even when there is a single statement to run. I feel this is ugly and also cluttering.

if (condition)
{
    statement1;
}
else
{
    statement2;
}

In my opinion, in order to get both high readability and maintainability the braces are not needed, unless at least one of the branches (if, else if, else) has more than one statement to run:

if (condition1)
    statement1;
else
    statement2;
if (condition2)
{
    statement3;
}
else
{
    statement4;
    statement5;
}

 

Advertisements

About Sorin Dolha

My passion is software development, but I also like physics.
This entry was posted in .NET, C# and tagged , , , , . Bookmark the permalink.

Add a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s