Ingo Rammer Technology Consulting
» IngoRammer.com
» My Books
» Conferences
» Consulting & Services
» Newsletter
 
 
 
» Contact
 

What's in a Type's Name?
April 07, 2003 06:43 PM

Sam is heavily in favor of using the BCL’s type names versus C#’s names. I absolutely second this for the very reason he states.

At the end of the day, nobody wants to end up with code like this, right?

static void MyMessagebox(HWND hWnd,
      LPCTSTR lpText,
      LPCTSTR lpCaption,
      UINT uType,
      WORD wLanguageId)
{
  System.Windows.Forms.MessageBox.Show(lpText,lpCaption);
}

Scary? Well ... it’s in fact completely legal C# code taken from the following program:

using System; 


using WORD = System.Int16;
using HWND = System.Int32;
using LPCTSTR = System.String;
using UINT = System.UInt32;

class ScaryThing
{
  static void MyMessagebox(HWND hWnd,
   
LPCTSTR lpText,
   
LPCTSTR lpCaption,
   
UINT uType,
   
WORD wLanguageId)
  
{
   
System.Windows.Forms.MessageBox.Show(lpText,lpCaption);
 
}

[STAThread]
  static void Main(string[] args)
 
{
   
LPCTSTR foo = "Foo";
   
LPCTSTR bar = "Bar";
   
MyMessagebox(0,foo,bar,0,0);
 
}
}

But you wouldn't want to, would you? So why does the use of LPCTSTR feel wrong, whereas the use of string instead of System.String doesn't? All three are equally right or wrong, but believe me - only the BCL name System.String is universally understood.

Lesson's learnt:

  • Use the BCL type names
  • Don't redefine your type's names to match your old habits ;-)

Trackback/Responses

TrackBack URL: http://stage.ingorammer.com/mt/mt-tb.cgi?tb_id=927

Comments
Post a comment

Remember personal info?










© 2002, 2003 by Ingo Rammer (ingo@ingorammer.com). Information is provided as-is and is subject to heavy changes due to its pre-release character.