Code/Tea/Etc...

Duncan Mackenzie has too much time on his hands

Int32 or Integer/int?

Brad Abrams posted about the use BCL types vs. language specific type names (in sample code) today, which just happens to be a topic I've had to think about myself when writing sample code for my own articles, so I thought I would make a comment.

I'm with Morty on this one... I have the general rule that sample code should be written following the style and convention guidelines for the language. I'm a VB guy, so this usually takes the form of "Write VB code the VB way", but there are exceptions.... For example, I use Integer in my Visual Basic .NET code, not Int32, but I like to use Int32 in Win32 API declarations; the specific size of integer is pretty important at that point so I like to make it clear... Beyond types it gets a little murky... I always use the System.IO classes for File access; VB.NET still has the Open/Put commands but I truly believe that those "legacy" statements are not as good/clear as the new System.IO classes... whereas in the case of Int32 vs. Integer (or MsgBox vs. MessageBox.Show()) it is merely a syntax/style difference.

I think using Int32 in a VB.NET/C# code sample makes it slightly less familar to a C++ developer (in the case of C#) or a VB6 developer (in the case of VB6)... and that makes the developer a little less comfortable, and therefore a little less likely to understand what they've been shown. The purpose of a sample is to explain the concept in terms of code. The purpose of doing in more than one language is to explain the concept in terms that the developer is already familiar with... well, following that same guideline and knowing that a VB.NET developer is more familar with Integer than Int32, they will benefit more from seeing the sample written using the VB data type names.

Of course, all of this can be ignored if Int32 was the class being demonstrated :)

Published Saturday, April 05, 2003 11:50 PM by Duncanma

Comments

 

Darren Neimke said:

Duncan,

at the fear of being labelled a Luddite for talking about stuff I probably don't understand :-) here goes...

I certainly don't want to get into a debate over this but, shouldn't the question be: "what is it best to use?".

I'm probably biased because I never really programmed in any typed languages before .NET, but, to me at least, being as explicit as possible is always a good thing.

I know that Int32 will map to System.Int32 even in version 30 of the Framework. God knows what Integer or int will map to by then.

Or am I deluded on this one? Feel free to call me a Luddite if you like, I've been told by the best of them that I make a lovely Luddite ;-)
April 6, 2003 12:37 AM
 

TrackBack said:

A little 'bit' more on Int32 vs Integer : Code/Tea/Etc...
April 5, 2003 11:50 PM
Anonymous comments are disabled

This Blog

Syndication

News

This blog has moved to my own VB site

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker