C# Coding Guidelines

Brad Abrahms has made a bold move and provided a version of some internal coding style guidelines on his blog thereby inviting a flame war.  🙂  It mostly looks good to me except for one item – you just knew there had to be at least *one* thing that everyone will disagree with.  Here’s the one I disagree with:

Do not use a prefix for member variables (_, m_, s_, etc.). If you want to distinguish between local and member variables you should use “this.” in C# and “Me.” in VB.NET.

Using some form of decoration on instance variables is beneficial in my opinion.  The problem with using this is that the compiler will compile up the resulting code just fine if you forget to apply "this.".  Then the resulting code is harder to read because I can’t easily disambiguate between local, instance and static variables.  We currently recommend using m_ for instance variables and s_ for static variables.  In this case, forgetting the "m_" later on doesnt’ work because the code won’t compile.  However I find myself starting to like the simpler "_" approach but then what do I do to know if a var is a static?  I am also starting to long to use the all caps naming convention for non-public constants e.g. private int BUFFER_SIZE;

Advertisements
This entry was posted in Software Development. Bookmark the permalink.

Leave 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