VB.NET Integer data types

  • Thread starter Thread starter Shawn Berg
  • Start date Start date
S

Shawn Berg

Is the Integer data type deprecated? I am not sure what Integer data type to
use in some of my classes.

According to the URL below, if I am reading it correctly, it seems as though
I should be using the Short, Integer, and Long data types. Is this correct?
Or should I instead be using the Int16, 32, and 64 data types in my code?
Whats the best practice here?

http://www.ondotnet.com/pub/a/dotnet/2001/07/30/vb7.html?page=2
 
This has been debated a few times on the NGs.
In general, the consensus is to use the Short, Integer, and Long keywords.
They of course translate directly to the Int16, 32, and 64 data types.
The debate has mostly been "will the underlying type vary in the future?"
At some point, it probably will, just has it has changed now.
But that time isn't in the foreseeable future. Maybe when the standard
processor architecture is 128bit or something.

However, in the cases where you know you need a specific size, which is
usually limited to external API calls and I/O, then I prefer to explicitly
declare the size. For me, when I see a declaration of Int32, that tells me
that I know I need exactly 32 bits for some reason. While it is no different
than "Integer", it is more "explicit" and serves as a flag to me when
reading my code later on that it might not be safe to alter the size.

As far as platform dependence, .NET has given us the IntPtr (Integer
Pointer) type. This is the one you should pay attention to. The underlying
type can vary based on whether you are on a 32 or 64 bit platform. Clearly
it should be used for pointers.

Gerald
 
Even though I use C++ .NET, I am faced a similar situation. I find it easiest
to use the language-specific names(short, int, long) when decaring variables,
but if is need to use it in an array decaration I use the .NET-specific
names(Int16, Int32, Int64). That way it takes less time to type, since there
really is no difference between the 2. I hope this helps.
 
Shawn,

The integer should give you the most properiate processor format. (with the
most performance). For the windows 32 bits operating systems is that 32
bits.

As Gerald tells are there a lot of discussions in the newsgroups if the
integer should stay 32 bits.

In my opinion would mean that the developer of that language will be the
looser in time in my opinion.

Any format (larger or smaller) that does not fit the register format needs
more cycles to proccess.

I hope that this helps,

Cor
 
Back
Top