<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: KinsonDigital</title>
    <description>The latest articles on DEV Community by KinsonDigital (@kinsondigital).</description>
    <link>https://dev.to/kinsondigital</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F116674%2Fb9818a8e-c9e9-4a2b-b368-c1d9d857802b.jpg</url>
      <title>DEV Community: KinsonDigital</title>
      <link>https://dev.to/kinsondigital</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kinsondigital"/>
    <language>en</language>
    <item>
      <title>Coding standards. Why and how with C#</title>
      <dc:creator>KinsonDigital</dc:creator>
      <pubDate>Fri, 04 Feb 2022 04:20:31 +0000</pubDate>
      <link>https://dev.to/kinsondigital/coding-standards-why-and-how-with-c-lm6</link>
      <guid>https://dev.to/kinsondigital/coding-standards-why-and-how-with-c-lm6</guid>
      <description>&lt;p&gt;Sigh.  Coding standards.  &lt;/p&gt;

&lt;p&gt;Ever have this experience?&lt;br&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flbzsld81sqrd8rp9y5v2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flbzsld81sqrd8rp9y5v2.jpg" alt="Code Review Experience"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After an interaction like that, you walk away feeling like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fje0mo46tydfndff0ja6e.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fje0mo46tydfndff0ja6e.gif" alt="Long Sigh"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm sure everybody at one point in their coding career went through this when your PR was getting code reviewed.&lt;br&gt;
What a shame!! &lt;/p&gt;


&lt;h2&gt;
  
  
  Coding standards?  Uhhh...why? 🤔
&lt;/h2&gt;

&lt;p&gt;I have had both good and bad experiences being on teams with and without coding standards.  Unfortunately, this is a human problem, not a technical one; solving the human issue is WAY more complicated!&lt;/p&gt;

&lt;p&gt;But it doesn't mean that using technology can't help improve things!!&lt;/p&gt;

&lt;p&gt;To help eliminate the issues that come with the pull request and code review processes, we can use technology to help shift our minds away from the little things like bracing style or spacing around parentheses.  We should concentrate on things that bring value, such as architecture and code comprehension. But why do these things manually when technology can do it for us?  With the manual process out of the way, we can keep the focus on what matters most; producing value.&lt;/p&gt;

&lt;p&gt;I love coding standards for this very reason.  We're not trying to "force" people to code the way we do. We want to get the team on the same page so we can concentrate on more important things.&lt;/p&gt;

&lt;p&gt;Remember, there is no "wrong" way to code; just different ways to code.  It depends on a variety of things like: language, the purpose of the code and software, the people on the team, and more.&lt;/p&gt;


&lt;h2&gt;
  
  
  Can .NET  do this with the associated tooling?
&lt;/h2&gt;

&lt;p&gt;Different platforms, languages, and tech stacks have capabilities to enforce and standardize your codebases.  Each has positives and negatives and their own quirks.  Fortunately, Microsoft and the .NET stack and associated tooling such as &lt;a href="https://visualstudio.microsoft.com/vs/" rel="noopener noreferrer"&gt;Visual Studio&lt;/a&gt; and &lt;a href="https://www.jetbrains.com/rider/" rel="noopener noreferrer"&gt;JetBrains Rider&lt;/a&gt; have fantastic capabilities to help with this kind of thing.&lt;/p&gt;


&lt;h2&gt;
  
  
  Uhhh...how? 🤔
&lt;/h2&gt;

&lt;p&gt;It depends on what kind of tooling you use.  No worries, it's easy to do.&lt;br&gt;&lt;br&gt;
In the .NET world, enforcing coding standards is done by using an &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;You're probably thinking, "what is an &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file"?  It's simply a text file that uses syntax similar to an &lt;strong&gt;INI&lt;/strong&gt; file.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__wikipedia--container"&gt;
  &lt;div class="ltag__wikipedia--header"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fwikipedia-logo-0a3e76624c7b1c3ccdeb9493ea4add6ef5bd82d7e88d102d5ddfd7c981efa2e7.svg" class="ltag__wikipedia--logo" alt="Wikipedia Logo"&gt;
    &lt;a href="https://en.wikipedia.org/wiki/INI_file" rel="noopener noreferrer"&gt;INI file&lt;/a&gt;
  &lt;/div&gt;
  &lt;div class="ltag__wikipedia--extract"&gt;&lt;p&gt;An &lt;b&gt;INI file&lt;/b&gt; is a configuration file for computer software that consists of plain text with a structure and syntax comprising key–value pairs organized in sections. The name of these configuration files comes from the filename extension &lt;i&gt;INI&lt;/i&gt;, short for initialization, used in the MS-DOS operating system which popularized this method of software configuration. The format has become an informal standard in many contexts of configuration, but many applications on other operating systems use different file name extensions, such as &lt;i&gt;conf&lt;/i&gt; and &lt;i&gt;cfg&lt;/i&gt;.&lt;/p&gt;&lt;/div&gt;
  &lt;div class="ltag__wikipedia--btn--container"&gt;
      &lt;a class="ltag__wikipedia--btn" href="https://en.wikipedia.org/wiki/INI_file" rel="noopener noreferrer"&gt;View on Wikipedia&lt;/a&gt;&amp;gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Adding this file in your project will give instructions to the tooling on what to enforce, what not to enforce, and at what level to enforce it.&lt;/p&gt;

&lt;p&gt;Let's go over how to add an &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file to a C# project in &lt;strong&gt;Visual Studio&lt;/strong&gt; first.  Don't worry,we'll cover &lt;strong&gt;JetBrains Rider&lt;/strong&gt; afterward.&lt;/p&gt;




&lt;h2&gt;
  
  
  Adding an editor config file to a project using Visual Studio (2022)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Right-click the project you want to add the &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file to.&lt;/li&gt;
&lt;li&gt;Choose the &lt;strong&gt;&lt;em&gt;Add&lt;/em&gt;&lt;/strong&gt; menu item.&lt;/li&gt;
&lt;li&gt;In the sub-menu, click the &lt;strong&gt;&lt;em&gt;New EditorConfig&lt;/em&gt;&lt;/strong&gt; menu item.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90ww2oni2zo5w4ize389.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90ww2oni2zo5w4ize389.gif" alt="Add editorconfig using Visual Studio"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to see the contents of the editorconfig, open the file in &lt;strong&gt;VS Code&lt;/strong&gt; or any text editor.&lt;/p&gt;

&lt;p&gt;Ok, sweet!  We have our &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file.  But wait! It's pretty much empty!  What the 🤬? What's goin' on here?&lt;/p&gt;

&lt;p&gt;Let me explain.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; files are just text.  There is only one rule with a comment at the top of the file. The &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; UI is a new feature that was introduced in the past couple years.  Even though the file is pretty much empty, the UI shows that there are many rules that aren't visible in the file.  This is because a new &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file will use all of the default values for all of the rules.  Once you change a rule value in the UI to something other than the default value, it will automatically insert that rule into the &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file.  Basically, if the rule is not in the file, then it is using the default value and there is no need to have the rule in the file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcictpi9ujgxta2lwm7qb.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcictpi9ujgxta2lwm7qb.gif" alt="Add editorconfig using Visual Studio"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Setting rules using Visual Studio (2022)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;When a quick action with a 💡icon shows on the left side, click the little down arrow to fly out a tiny menu.&lt;/li&gt;
&lt;li&gt;Choose the &lt;strong&gt;&lt;em&gt;Suppress or Configure issues&lt;/em&gt;&lt;/strong&gt; item at the bottom to display another menu flyout&lt;/li&gt;
&lt;li&gt;Choose the type of configuration you want to apply&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it!!  An entry for the configuration you have chosen will automatically be added to the &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file.  Of course, you can always just add the setting manually as well.&lt;/p&gt;

&lt;p&gt;Refer to the GIF 👇🏼 below to see it in action.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5n4h5k4pe4457bucpk3r.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5n4h5k4pe4457bucpk3r.gif" alt="Adding rule with Visual Studio"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Adding an editor config file to a project using JetBrains Rider
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Right-click the project you want to add the &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file to.&lt;/li&gt;
&lt;li&gt;Choose the &lt;strong&gt;&lt;em&gt;Add&lt;/em&gt;&lt;/strong&gt; menu item.&lt;/li&gt;
&lt;li&gt;In the sub-menu, click the &lt;strong&gt;&lt;em&gt;New EditorConfig&lt;/em&gt;&lt;/strong&gt; menu item.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo8hcno5rezgrvmz5g68s.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo8hcno5rezgrvmz5g68s.gif" alt="Add editorconfig using JetBrains Rider"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Ok, sweet!  We have our &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file.  But wait! It's empty!  Seriously? 🤦🏼‍♂️&lt;br&gt;&lt;br&gt;
It's ok.  We can still setup the rules. 👇🏼&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting rules using JetBrains Rider
&lt;/h2&gt;

&lt;h3&gt;
  
  
  TL;DR
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;JetBrains Rider&lt;/strong&gt; rules can only be edited manually.&lt;/p&gt;

&lt;h3&gt;
  
  
  Long Explanation 🥱
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;JetBrains Rider&lt;/strong&gt; support for &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; files, analyzing code, and enforcing standards are top-notch.  They support advanced use of the file format and let you mix &lt;strong&gt;Resharper&lt;/strong&gt;, &lt;strong&gt;.NET&lt;/strong&gt; specific standard rules, and &lt;strong&gt;StyleCop&lt;/strong&gt; rules in the file.  In my opinion, it is the best in the industry.  But, as we know, every piece of software does things differently.  &lt;/p&gt;

&lt;p&gt;But the downside is that &lt;strong&gt;JetBrains Rider&lt;/strong&gt; does not automatically insert the rules into the config file.&lt;br&gt;&lt;br&gt;
But don't worry.  I have a feeling that this feature will be coming to &lt;strong&gt;Rider&lt;/strong&gt;.  It was recently added to &lt;strong&gt;Visual Studio&lt;/strong&gt;. &lt;br&gt;
However, for some reason, configuring rules using action lists adds the configuration to the &lt;strong&gt;&lt;em&gt;.sln.DotSettings&lt;/em&gt;&lt;/strong&gt; file, not the &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; file.  This is one of the ways that &lt;strong&gt;JetBrains Rider&lt;/strong&gt; let's you share rules with the team by committing them to your Git repository.&lt;/p&gt;

&lt;p&gt;That said, if somebody knows how to interactively setup rules in &lt;strong&gt;JetBrains Rider&lt;/strong&gt; with the UI, let me know!!&lt;br&gt;
I looked into the documentation and found &lt;a href="https://www.jetbrains.com/help/resharper/2022.1/Using_EditorConfig.html#edit-editorconfig-interactively" rel="noopener noreferrer"&gt;this&lt;/a&gt;, but I couldn't find the settings on how to do it.&lt;/p&gt;

&lt;p&gt;Let's show how to manually enter a single rule.👇🏼&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3c9zhk3dxfe98l1gpeff.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3c9zhk3dxfe98l1gpeff.gif" alt="Adding rule with JetBrains Rider"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Ok, let's be realistic here.  Every project has its unique requirements, oddities, and edge cases.  Because of these reasons, each project requires its own coding standards. This isn't a one-size-fits-all scenario.&lt;/p&gt;

&lt;p&gt;I love having standards put into place because it brings my projects and me a great deal of value.  More importantly, it brings value to my users!  My open-source projects &lt;a href="https://github.com/KinsonDigital/Velaptor" rel="noopener noreferrer"&gt;Velaptor&lt;/a&gt; and &lt;a href="https://github.com/KinsonDigital/CASL" rel="noopener noreferrer"&gt;CASL&lt;/a&gt; require consistency and strictness due to their low-level nature.  Using the tooling and &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; files helps me achieve this.&lt;/p&gt;

&lt;p&gt;Cheers!!&lt;/p&gt;

&lt;p&gt;If you are interested in any of my projects and how I set up and use &lt;strong&gt;&lt;em&gt;.editorconfig&lt;/em&gt;&lt;/strong&gt; files and analyzers, check out my projects and list of resources below.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/DotNetAnalyzers/StyleCopAnalyzers" rel="noopener noreferrer"&gt;StyleCop Analyzers for the .NET Compiler Platform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.jetbrains.com/help/resharper/2022.1/EditorConfig_Index.html" rel="noopener noreferrer"&gt;Index of EditorConfig Properties&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options?view=vs-2022" rel="noopener noreferrer"&gt;Overview of .NET source code analysis&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2022" rel="noopener noreferrer"&gt;MS Docs / EditorConfig&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://editorconfig.org/" rel="noopener noreferrer"&gt;editorconfig.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devhints.io/editorconfig" rel="noopener noreferrer"&gt;Editor Config Cheat Sheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;If your interested in the rules that I use for &lt;a href="https://github.com/KinsonDigital/Velaptor" rel="noopener noreferrer"&gt;Velaptor&lt;/a&gt; and &lt;a href="https://github.com/KinsonDigital/CASL" rel="noopener noreferrer"&gt;CASL&lt;/a&gt;, refer to the GISTS that I created.  Use them in your projects and tweak as necessary!!

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/CalvinWilkinson/60f39b137febee0c67c0c75864d1ad2a" rel="noopener noreferrer"&gt;Solution Level Config&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/CalvinWilkinson/578959b4e03c90a7a954faf6ccfe6513" rel="noopener noreferrer"&gt;Unit Test Project Level Config&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>csharp</category>
      <category>codingstandards</category>
      <category>visualstudio</category>
      <category>rider</category>
    </item>
  </channel>
</rss>
