Giter Club home page Giter Club logo

sharp-column-indenter's Introduction

Sharp Column Indenter - Visual Studio Extension

A Smart source code indenter that indent the code into columns. Also known as "code alignment".

Download

Contents

  • Why Sharp Column Indenter?
  • What Is Column Indention / Code Alignment?
  • Examples Of Improvements In Code Readability Using Code Alignment
  • Steps To Use Sharp Column Indenter

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:

        y   = 2x
        y/2 = x

some code here 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:

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

The idea that Iโ€™m talking about is to use something like this below,

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

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:

  var benita = new Person() { Name = "Benita" };
  var deedeeAlmon = new Person() { Name = "Deedee Almon Fonsec" };
  var chaseHussain = new Person() { Name = "Chase Hussain" };
  var cordia = new Person() { Name = "Cordia" };

  benita.Age = 35;
  deedeeAlmon.Age = 12;
  chaseHussain.Age = 24;
  cordia.Age = 22;

same code with column indention,

  var benita       = new Person ( ) { Name = "Benita"              } ; 
  var deedeeAlmon  = new Person ( ) { Name = "Deedee Almon Fonsec" } ; 
  var chaseHussain = new Person ( ) { Name = "Chase Hussain"       } ; 
  var cordia       = new Person ( ) { Name = "Cordia"              } ; 

  benita       . Age = 35 ; 
  deedeeAlmon  . Age = 12 ; 
  chaseHussain . Age = 24 ; 
  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.

Step 2: Select Apply Column Indention command in Edit menu

sharp-column-indenter's People

Contributors

kudchikarsk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sharp-column-indenter's Issues

Feature request: Add options to customize the reformatting

When I run this extension my code is restyled as follows:

Original code:

			this.mapProps.Add( "TableType", (ushort)0x3 );
			this.mapProps.Add( "CharType", "ANSI" );
			this.mapProps.Add( "UnicodeCollation", "" );
			this.mapProps.Add( "LockMode", (ushort)0x1 );
			this.mapProps.Add( "SecurityMode", (ushort)0x2 );
			this.mapProps.Add( "ServerType", null );
			this.mapProps.Add( "ShowDeleted", false );
			this.mapProps.Add( "IncrementUserCount", false );
			this.mapProps.Add( "StoredProcedureConnection", false );
			this.mapProps.Add( "EncryptionPassword", null );
			this.mapProps.Add( "DbfsUseNulls", false );

After formatting:

			this . mapProps . Add ( "TableType"                 , ( ushort ) 0x3 ) ; 
			this . mapProps . Add ( "CharType"                  , "ANSI"   )       ; 
			this . mapProps . Add ( "UnicodeCollation"          , ""       )       ; 
			this . mapProps . Add ( "LockMode"                  , ( ushort ) 0x1 ) ; 
			this . mapProps . Add ( "SecurityMode"              , ( ushort ) 0x2 ) ; 
			this . mapProps . Add ( "ServerType"                , null     )       ; 
			this . mapProps . Add ( "ShowDeleted"               , false    )       ; 
			this . mapProps . Add ( "IncrementUserCount"        , false    )       ; 
			this . mapProps . Add ( "StoredProcedureConnection" , false    )       ; 
			this . mapProps . Add ( "EncryptionPassword"        , null     )       ; 
			this . mapProps . Add ( "DbfsUseNulls"              , false    )       ; 

This is not my desired output:

  1. It should not add spaces around the member-access operator . or method parens ().
  2. When a line is an assignment or method call then don't pre-pad the semicolon.
  3. When aligning on commas in a method call, don't format the parameter arguments (e.g. how (ushort)0x3 became ( ushort ) 0x3).

So my desired output is:

			this.mapProps.Add( "TableType"                 , (ushort)0x3 );
			this.mapProps.Add( "CharType"                  , "ANSI"      ); 
			this.mapProps.Add( "UnicodeCollation"          , ""          ); 
			this.mapProps.Add( "LockMode"                  , (ushort)0x1 );
			this.mapProps.Add( "SecurityMode"              , (ushort)0x2 );
			this.mapProps.Add( "ServerType"                , null        ); 
			this.mapProps.Add( "ShowDeleted"               , false       ); 
			this.mapProps.Add( "IncrementUserCount"        , false       ); 
			this.mapProps.Add( "StoredProcedureConnection" , false       ); 
			this.mapProps.Add( "EncryptionPassword"        , null        ); 
			this.mapProps.Add( "DbfsUseNulls"              , false       ); 

I appreciate some people might want this - so I'd like it to be an option for this extension in the Options window.

Thank you!

vs2019

Hi, can you update for 2019?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.