Interesting Results In VB.Net

  • Thread starter Thread starter Mythran
  • Start date Start date
Mythran said:
Cor Ligthert said:
Rinze,

You should try it, beside more efficient is it even quicker when you are
making a program.

Declaring global variables in the Main Section is something from the Cobol
time and very inefficient.

Cor



I used to be the same way, only dimensioning my vars at the top of the
method block...but now, after I tried it and used it...it isn't as ugly as I
thought it to be. Just dimension at the first point you need to use it. I
usually try to dimension and initialize at the same time, that way, if I
don't need the var, it's easy to track down :)

HTH,
Mythran

I pretty much try to dim my vars in one place - at the begining of the
scope they are used. But, I also try to limit the scope to as small as
possible. So - My code might look like (well, I mostly code C#, but
since this is a VB group :)

Public Sub TheBestSubEver ()
Dim anInteger As Integer
Dim aString As String

anInteger = SomeValue

For i As Integer = 0 To SomeLargeIntegerValue
Dim anIntegerInThisScope As Integer
' Do really cool loopy stuff with i and anIntegerInThisScope
Next

aString = "Hurrray, were done!"
End Sub

Anyway... That's what I do :)
 
C-Services Holland b.v. said:
I just don't like dimming variables all over the place. It's a sure fire
way to lose one. I don't care if it works, I just find it plain ugly.

It may seem ugly to you, but to others who have to maintain the code it
is a little more difficult to decipher when and where it is used. It's
pretty much the defacto standard.

Brian
 
Cor said:
Rinze,

You should try it, beside more efficient is it even quicker when you are
making a program.

Declaring global variables in the Main Section is something from the Cobol
time and very inefficient.

Cor

Why do you assume I'm declaring everything global in main? I only
declare vars global when it's absolutely nescesary. Normally I declare
every var I need in a function/sub at the top of that particular
function or sub. I really don't see any advantage to declaring a
variable halfway in a sub in a loop. This has always been my little pet
peeve with Basic (or Clipper for that matter), plucking vars out of the
air when you need them.
 
Rinze,

Feel free to do it your way.

As I always say that there is seldom a best method in VB.

As Mythran I Use

For I as integer = 0 to end
Next.

But as you insist on
Dim I as integer
bla
bla
bla
bla
bla
for I = 0 to end
next

Than that is your own decission

Cor
 
Back
Top