---
title: "Stop The Brace Wars, Use StyleCop - Muhammad Rehan Saeed"
description: "StyleCop analyzes C# source code to enforce a set of style and consistency rules. Rehan advocates its use in this thought provoking article."
canonical_url: "https://rehansaeed.com/stop-brace-wars-use-stylecop/"
last_updated: "2014-02-08T00:00:00+00:00"
meta:
  author: "Muhammad Rehan Saeed"
  keywords: "C#,Standards,StyleCop"
  "og:description": "StyleCop analyzes C# source code to enforce a set of style and consistency rules. Rehan advocates its use in this thought provoking article."
  "og:image": "https://rehansaeed.com/_og/s/o_65ab07307e2a2fa5.png"
  "og:image:alt": "Stop The Brace Wars, Use StyleCop - Muhammad Rehan Saeed"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Stop The Brace Wars, Use StyleCop"
  "twitter:image": "https://rehansaeed.com/_og/s/o_65ab07307e2a2fa5.png"
  "twitter:image:alt": "Stop The Brace Wars, Use StyleCop - Muhammad Rehan Saeed"
---

> Index of every page on this site: [llms.txt](https://rehansaeed.com/llms.txt)

# [Stop The Brace Wars, Use StyleCop](https://rehansaeed.com/stop-brace-wars-use-stylecop/)

Posted 8 February 2014 - **3 min read**

![StyleCop](https://rehansaeed.com/_ipx/f_png&s_2560x1440/images/hero/StyleCop-1366x768.png)

There is an on-going war among developers. This silent war has claimed countless hours of developer time through hours wasted in pointless meetings and millions of small skirmishes over the style of each developers written code. This post outlines a peace treaty, a way forward if you will but first I will outline the problem.

# Unverscores Versus the 'this' Keyword Link to this section

This is the main battlefront where most time is wasted and where developers are most entrenched in their forward positions. To use underscores for your field names or the `this` keyword. I myself am in this `this` camp but neither has a clear advantage in the battlefield. The underscores make it marginally quicker to access your fields using intelli-sense, while the `this` keyword makes it quicker to differentiate class members from static members.

```cs
private int _property;

public int Property
{
    get { return _property; }
}
```

```cs
private int property;

public int Property
{
    get { return this.property; }
}
```

# The Brace War Link to this section

This lesser known conflict is where JavaScript styling has leaked into C#. The default formatting rules in visual studio usually quashes this conflict but there are still those who see white space as wasted space and will go the extra mile by changing the Visual Studio settings to 'fix' this problem. I personally stick to the defaults and find the other method hard to read, a small sacrifice of a few extra lines is worth the gain in readability.

```cs
public int Property
{
    get { return this.property; }
}
```

```cs
public int Property {
    get { return this.property; }
}
```

# Field, Property, Constructor and Method Ordering Link to this section

Some (like me), like to have all fields, properties, constructors and methods separated into their own groups. Others prefer fields grouped with properties, and members from implemented interfaces kept together. Again, there is no real right way, the former allows quick navigation to find what you need, while the latter allows quick navigation of members which relate to each other.

# Using Statements Inside or Outside the Namespace Link to this section

Here is one area where there is a clear advantage in one camp. As outlined in this [Stack Overflow post](http://stackoverflow.com/questions/125319/should-usings-be-inside-or-outside-the-namespace), adding using statements inside the namespace can sometimes save a few seconds of troubleshooting. Yet even here, Visual Studio lets us down by having using statements outside the namespace as the default.

# Stepping on Peoples Feet Link to this section

Looking at another developers code can be an interesting experience. The style, look and feel of any code can vary wildly, even if they are written in the same language. Many times, I have found it difficult to find what I'm looking for and it takes time to adjust to each unique style.

Many a time, these large differences can occur even in the same teams, reducing productivity. This leads to the inevitable 'standards' meetings, where a teams of developers sit in a room and discuss underscores versus `this` and other differences at length. My own experience is that each side is entrenched and hunkering down into their positions, not wanting to have to change their writing style. In the end, the majority wins out or people continue working in their own way and people get used to it.

# The Solution For Peace Link to this section

I would argue that as there is no clear superior coding style, it is a pointless waste of time arguing over it. However, there is something to be said for a commons coding style. This is where [StyleCop](http://stylecop.codeplex.com/) comes in. It is a set of style rules which can be applied to your C# code.

There need be no lengthy discussion or arguing over it. Keep the default rules (turn off the comment rules if you choose) and you quickly have a set of standards that can be universally applied and tested not just in your team but universally by all C# developers around the world.

Download some sample code from [GitHub](https://github.com) and be at ease at the familiar look to the hopefully well designed code. I paint a rosy picture but I see more and more developers using StyleCop. It takes a week to get used to the change in your writing style, I myself switched from underscores to `this` and have never looked back. You can too.

## Web Mentions

[What's this?](https://en.wikipedia.org/wiki/Webmention)

### 0 Linked

### 0 Replies

## GitHub Comments

### 5 Comments

[Comment on GitHub](https://github.com/RehanSaeed/rehansaeed.github.io/issues/116)

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed)

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Vince Panuccio (@vincpa)](https://camo.githubusercontent.com/eed1924b2b64da6c68460554f2ee2327c3db4b34decc04b9c03a115314df93b8/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f37613130353465313766336334316336366231623238643464366230393337393f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/eed1924b2b64da6c68460554f2ee2327c3db4b34decc04b9c03a115314df93b8/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f37613130353465313766336334316336366231623238643464366230393337393f733d393626643d6d6d26723d67) **Vince Panuccio ([@vincpa](https://github.com/vincpa))** commented on **2014-02-15 21:14:02**

I have integrated StyleCop in to my build process at the place I work and is a standard part of any new development project I undertake. For me a breach in rules means the build is broken.

I think it is important for the entire code base to remain in a consistent state and for personal preference to remain in personal projects.

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed)

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Muhammad Rehan Saeed](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67) **Muhammad Rehan Saeed** commented on **2014-02-17 08:54:53**

I totally agree with you.

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed)

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Philip Crawford](https://camo.githubusercontent.com/2023aeac17caa09afecad3cd43b093cd2335f6c4740fc4402c80eb9d54bb3bc7/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f63323336346138343230396664376634306139643737653562313164356432663f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/2023aeac17caa09afecad3cd43b093cd2335f6c4740fc4402c80eb9d54bb3bc7/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f63323336346138343230396664376634306139643737653562313164356432663f733d393626643d6d6d26723d67) **[Philip Crawford](http://manifest.ly/)** commented on **2014-06-18 18:55:46**

Good post. I think one thing to continually point out is that as developers, we spend the vast majority of our time *reading* code, not typing it. All too often people optimize for typing, which is the short lever, instead of focusing on what enables us to read and understand code quickly.

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed)

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020 (edited 12 May 2020)

[![Tim Long](https://camo.githubusercontent.com/470c19179d2355d8cd4f81d003788180b61a79f0cb2bbbb199e86ae340ae49ec/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f64663034373834323663306534376363356535353764353339316535323535643f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/470c19179d2355d8cd4f81d003788180b61a79f0cb2bbbb199e86ae340ae49ec/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f64663034373834323663306534376363356535353764353339316535323535643f733d393626643d6d6d26723d67) **[Tim Long](http://tigra-astronomy.com/)** commented on **2019-06-21 18:17:54**

I would say that you momentarily arrive at the right conclusion, then ignore it and repeat the same mistake one level of abstraction up.

The bit where I think you have the right conclusion is:

> I would argue that as there is no clear superior coding style, it is a pointless waste of time arguing over it.

And then you advocate imposing someone else's arbitrary standard. That is just the tyranny of the majority. The philosophy I take is that readable code is the important thing. For example, I put more value on meaningful field names than whether or not they start with an underscore or 'this'. Just call them what they are, and let the IDE tell you they are fields by the colour it shows them in, or by the IntelliSense pop-up that you get when you hover the mouse.

Let developers express themselves however they feel comfortable. If you can read the code, nothing else really matters.

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed)

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020 (edited 12 May 2020)

[![Muhammad Rehan Saeed](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67) **[Muhammad Rehan Saeed](https://rehansaeed.com/)** commented on **2019-06-24 09:59:46**

> I would say that you momentarily arrive at the right conclusion, then ignore it and repeat the same mistake one level of abstraction up.
>
> The bit where I think you have the right conclusion is:
> > I would argue that as there is no clear superior coding style, it is a pointless waste of time arguing over it."
>
> And then you advocate imposing someone else's arbitrary standard. That is just the tyranny of the majority. The philosophy I take is that readable code is the important thing. For example, I put more value on meaningful field names than whether or not they start with an underscore or 'this'. Just call them what they are, and let the IDE tell you they are fields by the colour it shows them in, or by the IntelliSense pop-up that you get when you hover the mouse.
>
> Let developers express themselves however they feel comfortable. If you can read the code, nothing else really matters.

Yes, that is totally a valid option. Let people do whatever they want. Free yourself from the shackles.

I only have a few counter arguments to that viewpoint. If everyone's code looks different, it might take a bit longer for people to parse it. I'd be interested to see some studies in how much time (if any) is wasted in this regard. I am assuming there is some. Then there is the social aspect. If I change a colleagues code, do I then use my style or theirs to modify a class? Does the class end up with a mix of coding styles? Finally, a lot of developers (only me?) are control freaks and my OCD starts acting up when I see code like that.

Thanks for raising that point. As obvious as it now seems, it's not one that occurred to me.

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://rehansaeed.com/#website","@type":"WebSite","description":"Software Developer at Microsoft, YouTuber, Open Source Contributor and Blogger","inLanguage":"en-GB","name":"Muhammad Rehan Saeed","url":"https://rehansaeed.com/","author":{"@id":"https://rehansaeed.com/#identity"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://rehansaeed.com/?search={search_term_string}"},"query-input":"required name=search_term_string"}],"publisher":{"@id":"https://rehansaeed.com/#publisher"}},{"@id":"https://rehansaeed.com/stop-brace-wars-use-stylecop/#webpage","@type":"WebPage","dateModified":"2014-02-08T00:00:00+00:00","datePublished":"2014-02-08T00:00:00+00:00","description":"StyleCop analyzes C# source code to enforce a set of style and consistency rules. Rehan advocates its use in this thought provoking article.","name":"Stop The Brace Wars, Use StyleCop","url":"https://rehansaeed.com/stop-brace-wars-use-stylecop/","breadcrumb":{"@id":"https://rehansaeed.com/stop-brace-wars-use-stylecop/#breadcrumb"},"isPartOf":{"@id":"https://rehansaeed.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://rehansaeed.com/stop-brace-wars-use-stylecop/"]}]},{"@id":"https://rehansaeed.com/#identity","@type":"Person","name":"Muhammad Rehan Saeed","url":"https://rehansaeed.com/about/","image":{"@id":"https://rehansaeed.com/#/schema/image/1"},"sameAs":["https://github.com/RehanSaeed","https://www.linkedin.com/in/muhammad-rehan-saeed","https://stackoverflow.com/users/1212017/muhammad-rehan-saeed","https://www.youtube.com/c/MuhammadRehanSaeed","https://www.twitch.tv/rehansaeeduk"]},{"@id":"https://rehansaeed.com/#publisher","@type":"Organization","logo":"https://rehansaeed.com/images/schema/Publisher-600x60.png","name":"Muhammad Rehan Saeed","url":"https://rehansaeed.com"},{"@id":"https://rehansaeed.com/stop-brace-wars-use-stylecop/#article","@type":"Article","dateModified":"2014-02-08T00:00:00+00:00","datePublished":"2014-02-08T00:00:00+00:00","description":"StyleCop analyzes C# source code to enforce a set of style and consistency rules. Rehan advocates its use in this thought provoking article.","headline":"Stop The Brace Wars, Use StyleCop","inLanguage":"en-GB","url":"https://rehansaeed.com/stop-brace-wars-use-stylecop/","author":{"@id":"https://rehansaeed.com/#identity"},"image":[{"@type":"ImageObject","url":"https://rehansaeed.com/images/hero/StyleCop-1366x768.png","caption":"StyleCop","width":"1366","height":"768"}],"isPartOf":{"@id":"https://rehansaeed.com/stop-brace-wars-use-stylecop/#webpage"},"keywords":["C#","Standards","StyleCop"],"mainEntityOfPage":{"@id":"https://rehansaeed.com/stop-brace-wars-use-stylecop/#webpage"},"publisher":{"@id":"https://rehansaeed.com/#publisher"}},{"@id":"https://rehansaeed.com/stop-brace-wars-use-stylecop/#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Blog","item":"https://rehansaeed.com/","position":1},{"@type":"ListItem","name":"Stop The Brace Wars, Use StyleCop","item":"https://rehansaeed.com/stop-brace-wars-use-stylecop/","position":2}]},{"@id":"https://rehansaeed.com/#/schema/image/1","@type":"ImageObject","contentUrl":"https://rehansaeed.com/images/author/Muhammad-Rehan-Saeed/Logo-512x512.png","inLanguage":"en-GB","url":"https://rehansaeed.com/images/author/Muhammad-Rehan-Saeed/Logo-512x512.png"}]}
```

## Sitemap

See the full [sitemap](https://rehansaeed.com/sitemap.md) for all pages.
