Prev: Array of pointers
Next: Will this object get destroyed?
From: dpb on 16 Oct 2009 12:55 Schmidt wrote: > "Eduardo" <mm(a)mm.com> schrieb im Newsbeitrag news:hb8uet$arf$1(a)aioe.org... > >>>> The 'Option Base' declaration could serve to set the dafault >>>> lower bound to 0, the opposite as it's in VB6. >>> It _does_ serve to set it at either on user choice as it should. >> I mean that the default should be 1. > > I'd vote against that - the "ZeroBased-thinking" is not only > there, because "C introduced it this way" ... it has math- > backgrounds and eases the Array-Handling in many > common Algorithms/Loops/scenarios. > > simple RingBuffer-example (i.e. implemented in a class): > ....[sample code elided for brevity]... > Or simple Buffer-growings, i.e. in a small StringBuilder-Class: > ....[sample code elided for brevity]... > Now, if you try to write all of the above with OneBased Arrays, > the whole "index-fiddling" would become much more "unnatural" > or "unelegant" (from a programmers point of view) ....... IMO ;-) Very nice demonstrations, Olaf! And BTW, for Eduardo the reallocation/MemCopy stuff of the latter is what has to happen "behind the scenes" in his proposed dynamic late array allocation scheme whether has to write it explicitly or not. Latest version of Fortran Standard (F2008) does, in fact incorporate its version of Basic strings (character variables) w/ variable length strings causing reallocation on assignment in some places (early versions of CHARACTER in F77 were fixed length, F90/95 introduced variable length but left some significant "holes" in where/how they could be used, primarily for compatibility reasons). In the Matlab group (comp.soft-sys.matlab) there are continuing discussions on the effect on performance of not "preallocating" arrays but letting them grow in loops that can be studied for a beginning understanding of how that decision to allow that feature while providing syntactical benefits has very real costs associated with it. --
From: Eduardo on 16 Oct 2009 13:23 > Now, if you try to write all of the above with OneBased Arrays, > the whole "index-fiddling" would become much more "unnatural" > or "unelegant" (from a programmers point of view) ....... IMO ;-) What I mean is not that the 0 based arrays should not be possible, but when you don't specify the lower bound (and don't have any declaration such as "option Base"), its default should be 1. Of course there are situations when 0 based is more appropriate, or even required, but _my opinion_ is that in general (and not just for me), there are many more situation that 1 based is more natural. But this must come along with automatic redim, otherwise it could make the things worse. The goal is that the programmer could concentrate his/her efforts in the functions of his program and not in the technical problems of the language. Yes, you lose the possibility of "not the check arrays bounds" in the compiler options. In that case, if you opt for the option of not checking it (the bounds) in order to get some speed increase, you'll have to redim the arrays in your code as it's today. You don't lose anything, because if you want to program as today, you can.
From: Eduardo on 16 Oct 2009 13:32 Scott M. escribi�: > I'm for the zero-based array, not because it's easier or harder than > something else. I think ANY programmer (even a new one) has to be adept > enough with numbers and math to be able to handle a list that starts with 0 > and/or a list that starts with 1 - I really don't think that is a > show-stopper. > > The reason I'm for zero-based arrays is simply because, im my experience, > zero-based is the more common approach in most modern programming languages > and since these days, programmers are being asked to become familiar with > more than just one language, having more of them support the same standard > makes jumping back and forth easier and makes careless mistakes because over > there I use zero, but over here I use 1, not an option. > > We haven't even mentioned that in corporate America (and corporate > non-America), programmers don't program in a vacuum. They write code that > must integrate with other code. Having all programmers code according to > the default array starting index just makes more sense to me in an > Enterprise, than having some people use one and others using zero. Can you > say "standards"? > > Just my 1 cents (but please start your cent count from zero). OK, those are valid reasons, but then it means that the programmers have to carry "a karma" forever and ever just because something is too commonly used? Some language must be the first in changing that. (Asumming that it would be better in the other way, that it's also under discussion.) I'm not saying I'm definitely right, may be I'm wrong, but that's the way I see it.
From: Eduardo on 16 Oct 2009 13:39 > Yes, you lose the possibility of "not the check arrays bounds" in the > compiler options. > In that case, if you opt for the option of not checking it (the bounds) > in order to get some speed increase, you'll have to redim the arrays in > your code as it's today. > > You don't lose anything, because if you want to program as today, you can. I had another idea about the redim issue: Just leave everything as it's now but add another intruction: AutoDim AutoDim myArray (1) as String The number indicates the lower bound.
From: Schmidt on 16 Oct 2009 13:34
"Nobody" <nobody(a)nobody.com> schrieb im Newsbeitrag news:u88FHDoTKHA.3404(a)TK2MSFTNGP04.phx.gbl... > > I'd vote against that - the "ZeroBased-thinking" is not only > > there, because "C introduced it this way" ... it has math- > > backgrounds and eases the Array-Handling in many > > common Algorithms/Loops/scenarios. > > I think you already know this, but didn't mention it. Using 1 would > also have a small performance hit, because the compiler has to > subtract one from the index. Yep. > While the compiler can do the subtraction at compile time in > certain cases, Ex: A(5), it cannot do that when a variable is > used as the index. Yes, an array represents an allocated memory-chunk with a startaddress. And array-indexes are (calculated) *Offsets* to that startaddress. And the first element in an array has naturally Offset 0 then, so why not transport that directly into the "index-mapping". It's just the natural way, especially when dealing with languages, which work more "to the metal" (dealing with pointers directly) where all that "zerobased-offset-thinking" makes a whole lot more sense and usually results in shorter writable constructs (from a programmers view), and often also better "hints" (from the "compilers point of view") ... as for example in the C-language (which Scott BTW just classified as one of the "modern languages" these days... ;-)) Olaf |