Int32 or Integer/int?

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 href="">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 🙂

Comments (2)

  1. Anonymous says:

    A little ‘bit’ more on Int32 vs Integer : Code/Tea/Etc…

  2. 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 😉

Skip to main content