Correct naming (FxCop)

Often developers are not sure how to name things (e.g. fileName or filename, barCode or barcode). Here it is how you should do it:

   1: //-----------------------------------------------------------------------
   2: // <copyright file="Naming.cs" company="hfrmobile.com">
   3: //   Copyright (c) by Harald-René Flasch
   4: // </copyright>
   5: //-----------------------------------------------------------------------
   6:  
   7: using System;
   8:  
   9: namespace FxCopTests
  10: {
  11:     /// <summary>
  12:     /// Avoid creating compound words from terms which exist in the dictionary as discrete terms.
  13:     /// Do not create a compound word such as 'StopWatch' or 'PopUp'. These terms are recognized
  14:     /// in the dictionary and should be cased as 'Stopwatch' and 'Popup'.
  15:     /// </summary>
  16:     public static class Naming
  17:     {
  18:         // CA1702: CompoundWordsShouldBeCasedCorrectly (NOT: EMail)
  19:         public static string Email
  20:         {
  21:             get { return "harald-rene.flasch@hotmail.com"; }
  22:         }
  23:  
  24:         // CA1702: CompoundWordsShouldBeCasedCorrectly (NOT: barCode)
  25:         public static string GenerateBarcode(string barcode)
  26:         {
  27:             return barcode;
  28:         }
  29:  
  30:         // CA1702: CompoundWordsShouldBeCasedCorrectly (NOT: unLoad)
  31:         public static string UnloadList(string list)
  32:         {
  33:             return list;
  34:         }
  35:  
  36:         // CA1702: CompoundWordsShouldBeCasedCorrectly (NOT: multiLingual)
  37:         public static string GenerateLanguage(string multilingual)
  38:         {
  39:             return multilingual;
  40:         }
  41:  
  42:         // CA1702: CompoundWordsShouldBeCasedCorrectly (NOT: filename)
  43:         public static string GenerateFile(string fileName)
  44:         {
  45:             return fileName;
  46:         }
  47:  
  48:         // No rule for Cleanup/CleanUp?
  49:         public static void CleanUp()
  50:         {
  51:         }
  52:  
  53:         // CA1702: CompoundWordsShouldBeCasedCorrectly (NOT: SetUp)
  54:         public static void Setup()
  55:         {
  56:         }
  57:  
  58:         // CA1702: CompoundWordsShouldBeCasedCorrectly (NOT: firstname, lastname, ...)
  59:         public static string GetFirstName(string firstName)
  60:         {
  61:             return firstName;
  62:         }
  63:  
  64:         // CA1702: CompoundWordsShouldBeCasedCorrectly (NOT: eMail)
  65:         public static string GetMailAddress(string email)
  66:         {
  67:             return email;
  68:         }
  69:     }
  70: }

If you are not sure how to name other things you should consider using Microsoft FxCop! Also if you are not sure how to format your code Microsoft StyleCop will be your friend!

About hfrmobile

Nice guy but with a sarcastic type of humor. I have combined hobby and profession and I am happy about this. At the moment I am holding MCP, MCSE (NT 4.0), MCTS and MCPD certificates. Having experience in developing software for more than 15 years. Started learning programming using Pascal, Assembler, C/C++. Also having experience with non-Microsoft products / programming languages (e.g. PHP). Most experiences at the moment: MySQL, MS-SQL, PL/SQL, ASP.NET, C#, Silverlight (Windows Phone) and WPF.
This entry was posted in Allgemein. 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