Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Could someone explain if there is any performance advantages between the two declaration snippets below or is it just a .exe file size issue?

 


Dim intX as Int32
Dim intY as Int32
Dim intZ as Int32

 


Dim intX, intY, intZ as Int32

My website
Posted

I doubt there is a difference at all. The compiler will most probably optimize his execution time anyway.

 

I recommend the upper style, though.

Makes it easier to read, comment and edit.

.nerd
  • *Experts*
Posted
I use the upper method for most things, because it allows you to initialize the variable, and use the 'New' keyword to initialize the object.
Posted

Also, (not sure if this carried over to .NET but) I think in 6.0, the lower style would only declare the specific type to the last var in the list.

e.g.

Dim var1, var2, var3 As Integer

this would end up with var1 & var2 as variable type Variant and only var3 would actually be an Integer. As I'm typing this, I'm having doubts as to weather or not this was the case, however, I seem to recall this hapening to me once or twice before I figured it out. If I'm just way out in left field (as usual...) just ignor me. I don't get much sleep these days!

Being smarter than you look is always better than looking smarter than you are.
Posted
Good to know, thanks Derek. Although, I'll be using the one line per declaration also, if for nothing more than out of habit. And I do find it easier to read.
Being smarter than you look is always better than looking smarter than you are.
Posted
Could someone explain if there is any performance advantages between the two declaration snippets below or is it just a .exe file size issue?

 


Dim intX as Int32
Dim intY as Int32
Dim intZ as Int32

 


Dim intX, intY, intZ as Int32

 

heh, this first way is easier to read, thes econd way takes up less space.. my mario game for instance, as about like 30 variables( i think) so i try to use the lower method

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

  • *Experts*
Posted
A good way to conserv space (is with regions):
#Region " Variables "
Dim blah As Blah
' ...
' ...
' ...
#End Region

Then you can simple expand and contract the region. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...