From: Schmidt on

"Eduardo" <mm(a)mm.com> schrieb im Newsbeitrag news:hbaa6n$vsq$1(a)aioe.org...
>
> > 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.
I've understood that you meant it that way - but the *default*
is IMO absolutely correct at Zero - not only from the compilers
point of view, but also the programmers.

> Of course there are situations when 0 based is more appropriate,

Speaking for myself - these situations happen far more often
in my coding, than situations where a onebased-index would
make more sense.

E.g. in a selfwritten "listbox" or something like that, where you
would have to calculate the Index-Offset into e.g. a String-
Array that holds your ListView-Lines you want to render
for example in ownerdraw-routines.

If everything is ZeroBased (also the Scroller-Min-Value), then
everything "feels and works just naturally" - i.e. you can
calculate the current ListIndex that was "just clicked" in a
MouseDown-Event for example this way:

ListIdx = (MouseY - HeaderHeight) \ RowHeight + VScroll.Value

Same thing nearly everywhere, where Integer-Division or
Modulo is required - the "length of something", divided
by something (or the remainder of such divisions, as shown
in the RingBuf-example), naturally "map directly" to zerobased
Offsets (also in the whole wide area of "Pixel-processing", etc.).

Olaf



From: Tom Shelton on
On 2009-10-16, Eduardo <mm(a)mm.com> wrote:
>> Well, if you are interested in standards, yes.
>
> But AFAIK there is still not "standard for lower bound in arrays in high
> level programming languages".
>

Well, there maybe no official standard - but I believe the defacto standard
has been established - and that's 0. I can't even think of a lanugage I've
ever used that defaulted to 1 as a base....

--
Tom Shelton
From: Scott M. on

"Eduardo" <mm(a)mm.com> wrote in message news:hbad09$3m1$1(a)aioe.org...
>> Well, if you are interested in standards, yes.
>
> But AFAIK there is still not "standard for lower bound in arrays in high
> level programming languages".
>
>
> It's just common use to be 0, but not an established standard.

True, but it's common enough where someone using C, C++, Java, .NET (oops,
sorry I know I'll get flamed for that one), and many others could reasonably
expect array indicies to start at zero. And, lets not forget that with VB
6, zero is the default as well. In all the years I worked with VB 6, I
never really found a compelling reason to use anything other than zero.

So, while not a programming "law", in my experience, zero is not so much the
"standard" as it is the "best practice".

> From the machine point of view, it's favored 0 based, but from a high
> level (human)...
>
> Unfortunately, I think that many people who decide in language design, is
> too much tending to think from the machine point of view.
> That's also why we have now 0-based as the "standard".

Absolutely, but you've got to remember why humans use computers in the first
place, to do jobs more efficiently than humans can do them. That means
catering to the way the hardware is designed to be used. The job of a
programmer is to bridge the gap between what the hardware wants and what the
human using the hardware wants. It really hasn't been an issue for a
programmer to give the system a zero, but give the user a one.

-Scott


From: Eduardo on
Karl E. Peterson escribi�:

> Sometimes, I "need" 1995 or 1982 or 2000 as the LBound. But I cope, especially in
> langauges that don't offer that option, by just adding a constant to the index
> if/when appropriate.

Those are special cases.

> Yeah, 0 is the *only* sensible default. I didn't appreciate that either, at first.
> Humans may often start counting at 1, but by no means do they always start there.

0 means nothing. 1 means 1.

For machines 0 means the first combination of bits, one combination= 1

Each number has a place, 0 has also a place, the place is address
00000000000000000000000000000000 (in 32 bits systems).

But each number has also a meanning, or a value.

So, we have the place of a number and the meanning (or value) or the number.

We could index the array with its place in the memory or with the
"counter" of items.

If we care about how the machine stores it, we should use 0, because 0
is the place of the first element. But if we care more about what item
is it in the total count, the first item is counted with 1, not with 0.

What do you care more and take more into account when indexing an array,
1) how the machines store it, or 2) what item is it in the total count
of items?

In other words: how to better index an array, with it's location in
memory or with the number of item it is?
From: dpb on
Eduardo wrote:
>> Well, if you are interested in standards, yes.
>
> But AFAIK there is still not "standard for lower bound in arrays in high
> level programming languages".

That's because there is no Standard for multiple languages (and cannot be).

> It's just common use to be 0, but not an established standard.

Each language _DOES_ have a standard whether it's proprietary (like VB
or Matlab) or a public one (like Fortran/C/C++/APL/ADA/...).

> From the machine point of view, it's favored 0 based, but from a high
> level (human)...
>
> Unfortunately, I think that many people who decide in language design,
> is too much tending to think from the machine point of view.
> That's also why we have now 0-based as the "standard".

Well, it's certainly not fruitful to design a language totally outside
being aware of what the implications of that design imply for
implementation. It would be hard to say that the design of C++ was
focused excessively on the machine in the development of classes,
templates, inheritance, ... I would say if anything, many of these
features go overboard the other direction in trying to add too much
abstraction that comes w/ a great deal of obfuscation and overhead.

OTOH, one of Fortran's explicit goals has been (and remains) to be able
to produce very good numeric code suitable for the large class of
machines upon which compilers are likely to be implemented and that has
features designed to either take advantage of (or at least not be hurt
by) the hardware. Specific things in the language are not implemented
as they are in, say C, because doing so prevents certain classes of
optimization that otherwise can make very large gains in performance.
The latest has specifically worked very hard at standardizing co-arrays
for parallel processing to attempt to make the application to that
increasingly common current architecture more user-friendly to code for.
How successful it will be is yet to be seen, but certainly while
looking at current hardware it's also a goal to not make decisions that
may penalize newer or different architectures.

OTOH, the Standards Committee has to make any changes very carefully to
be certain to not "break" legacy code which adds many other constraints
as to how or whether a feature is added. This is particularly true for
Fortran as it is probably the one language that has the most widespread
old code base in general reuse there is for numeric computing. That
resource simply cannot be abandoned.

But, if you are adamant that you personally want a programming language
that uses 1-based arrays as its default, then Fortran's your obvious
choice! :) Add to that it's very close similarity in basic (pun
intended :) ) syntax and that even array storage order in BASIC was
derived from that of FORTRAN to be column-major and you're good to go...

Expecting to see you as a regular on clf shortly!!! :)

--

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12
Prev: Array of pointers
Next: Will this object get destroyed?