Sharp Column Indenter - Visual Studio Extension

Contents

About Extension

Sharp Column Indenter is a smart source code indenter that indent the code into columns. Also known as ‘code alignment’.

Why Sharp Column Indenter?

The most important aspect of programming is the readability of the source code that you write or maintain. This involves many things, from the syntax of the programming language, to the variable names, comments, and indentation.

Here indention is something where Sharp Column Indenter can help you with.

What Is Column Indention / Code Alignment?

In mathematics you always keep your equals lined up directly underneath the one above. It keeps it clean and lets you know you’re working on the same problem, for example:

1 y   = 2x
2 y/2 = x            

Programming is slightly different. We often have a lot of assignments underneath each other, and while they are not strictly the same as maths, there is a close relationship. As such, aligning the equals allows us to quickly spot the relationship.

Further, it makes your code so much more readable. Without alignment, the code is like opening a CSV file in Notepad. But, if you open the CSV file in Excel, it becomes so much easier to read since the columns have meaning.

Examples Of Improvements In Code Readability Using Code Alignment

First example

Take a look at this code:

 1 //natural code with no code alignment and you can see that
 2 //readability of the code is not that good 
 3 var people1 = new List<Person>()
 4 {
 5   new Person { Name = "Benita", Location = "Bareilly India", Age = 25 },
 6   new Person { Name = "Deedee Almon", Location = "Bari Italy", Age = 32 } ,
 7   new Person { Name = "Chase Hussain", Location = "Barika Algeria", Age = 45 } ,
 8   new Person { Name = "Cordia", Location = "Barinas Venezuela", Age = 26 } ,
 9   new Person { Name = "Malvina Neff", Location = "Barisal Bangladesh", Age = 36 } ,
10   new Person { Name = "Erika ", Location = "Barnaul Russia", Age = 56 } ,
11   new Person { Name = "Lisabeth Terr", Location = "Barquisimeto Venezuela", Age = 67 } ,
12   new Person { Name = "Farrah ", Location = "Barra Mansa Brazil", Age = 57 } ,
13   new Person { Name = "Domonique Biv", Location = "Barrackpur India", Age = 57 } ,
14   new Person { Name = "Jonah", Location = "Barrancabermeja Colombia", Age = 34 }
15 };

The idea that I’m talking about is to use something like this below,

 1 //same above code with column indention
 2 var people2 = new List<Person>()
 3 {
 4   new Person { Name = "Benita"       , Location = "Bareilly India"          , Age = 25 }, 
 5   new Person { Name = "Deedee Almon" , Location = "Bari Italy"              , Age = 32 }, 
 6   new Person { Name = "Chase Hussain", Location = "Barika Algeria"          , Age = 45 }, 
 7   new Person { Name = "Cordia"       , Location = "Barinas Venezuela"       , Age = 26 }, 
 8   new Person { Name = "Malvina Neff" , Location = "Barisal Bangladesh"      , Age = 36 }, 
 9   new Person { Name = "Erika "       , Location = "Barnaul Russia"          , Age = 56 }, 
10   new Person { Name = "Lisabeth Terr", Location = "Barquisimeto Venezuela"  , Age = 67 }, 
11   new Person { Name = "Farrah "      , Location = "Barra Mansa Brazil"      , Age = 57 }, 
12   new Person { Name = "Domonique Biv", Location = "Barrackpur India"        , Age = 57 }, 
13   new Person { Name = "Jonah"        , Location = "Barrancabermeja Colombia", Age = 34 }  
14 };

The Sharp Column Indenter extension allows you to align by more than just the equals. As you start to see the benefits of alignment, you see that there is so much more to align with.

Compare these:

1 var benita = new Person() { Name = "Benita" };
2 var deedeeAlmon = new Person() { Name = "Deedee Almon Fonsec" };
3 var chaseHussain = new Person() { Name = "Chase Hussain" };
4 var cordia = new Person() { Name = "Cordia" };
5 
6 benita.Age = 35;
7 deedeeAlmon.Age = 12;
8 chaseHussain.Age = 24;
9 cordia.Age = 22;

same code with column indention,

1 var benita       = new Person ( ) { Name = "Benita"              } ; 
2 var deedeeAlmon  = new Person ( ) { Name = "Deedee Almon Fonsec" } ; 
3 var chaseHussain = new Person ( ) { Name = "Chase Hussain"       } ; 
4 var cordia       = new Person ( ) { Name = "Cordia"              } ; 
5 
6 benita       . Age = 35 ; 
7 deedeeAlmon  . Age = 12 ; 
8 chaseHussain . Age = 24 ; 
9 cordia       . Age = 22 ; 

By aligning by the dot we can clearly see that we are setting the same property on each variable, and the thing that changes is the variable name.

This might seem a bit crazy now, but once you start aligning things, it’s addictive.

Steps To Use Sharp Column Indenter

Step 1: Select text you want to align.

Select text you want to align

Step 2: Select Apply Column Indention command in Edit menu.

Select Apply Column Indention command in Edit menu

Thats it!

I turned Sharp Column Indenter project into a Github repo so you can, you know, contribute to it by making pull requests.

If you have constructive criticism, or know of other tools that do the same thing, please leave a comment.

Sharp Column Indenter - Visual Studio Extension
Share this

Subscribe to Code with Shadman