I do too.
Quote:
Before I make my point, allow me to qualify my statement. I know Assembler (console, not GUI), Java, VB6 and VB.Net.
Ok, I know assembler, C, C++, Java, VB, Perl, JavaScript, PHP, Pascal and Delphi.
Quote:
In the latter three, you can get the upper bound of an array automatically through Array.Length or UBound(Array).
My disagreement stems from the following points.
In order to know the size of an array without programmatically determining it requires that you keep a global variable (at least one with the same scope as the array) that keeps track of the array elements in which you will need to constantly modify that variable if you modify the size of your array.
So do those languages internally.
Quote:
This leads to code that is less easy to read,
Not if you give those variables good names. Where is the difference between
UBound(arr)
and
UBoundOfArr
?
Quote:
code that is more prone to error,
Why?
Quote:
and usually slower code as well. Slower because in the instance when I use an array that is dynamically sized, I usually do a large number of sizing and resizing during execution of my code. After all of that is done, I need to know the final size of my array. At that time, it is not going to change further. It is there I determine the size of the array.
Do you really want to know how VB handles arrays? It's not pretty, and it's terribly slow.
And resizing arrays often is always a bad idea, it is a sure way to waste time.
Quote:
If I had to store the array size as I resized and also resize, rather than resizing only, each iteration through the loop has more steps than necessary.
The problem of VB is that it is very likely that a seemingly innocent code line takes eons to execute.
Quote:
Sure, I'm aware that under normal operation, the speed difference would not be significant, but I'm currently using C++ to optimize some of my slower loops in VB.Net, where I currently have a working DirectX8 graphics engine. I want every piece of speed I can get. I would do it in Assembler, except for the fact that I have not been able to successfully link Assembler to DirectX.
You have chosen the right language to optimize.
I want to add that I once translated array-heavy VB code to C, it ran about 30 times faster...