Prev: Array of pointers
Next: Will this object get destroyed?
From: dpb on 16 Oct 2009 14:34 Eduardo wrote: .... > In other words: how to better index an array, with it's location in > memory or with the number of item it is? As everybody else has been saying, all depends on the situation. Sometimes one, sometimes another is better and it is not possible to generalize beyond that to any meaningful definition of "better". That's the point. --
From: dpb on 16 Oct 2009 14:43 dpb wrote: > Eduardo wrote: > ... > >> In other words: how to better index an array, with it's location in >> memory or with the number of item it is? > > As everybody else has been saying, all depends on the situation. .... That of course, is at the source code level. Either will be translated to 0-based offsets in implementation, universally "under the hood". --
From: Eduardo on 16 Oct 2009 14:53 > The job of a > programmer is to bridge the gap between what the hardware wants and what the > human using the hardware wants. OK, but the language could help a litle more to the programmer to do the job. > It really hasn't been an issue for a > programmer to give the system a zero, but give the user a one. It's not a "problem", it's an additional task to do the count in the mind when programming (0 means 1, 1 means 2, 2 means 3) that could be avoided.
From: Eduardo on 16 Oct 2009 15:09 Schmidt escribi�: > 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. Yep, the "issue" is too much spread. Also the first element of a listbox, etc, should be indexed with 1 and not 0. But that is too much to ask to change now.
From: Schmidt on 16 Oct 2009 15:51
"Eduardo" <mm(a)mm.com> schrieb im Newsbeitrag news:hbage9$805$1(a)aioe.org... > Schmidt escribi�: > > > 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. > > Yep, the "issue" is too much spread. > Also the first element of a listbox, etc, should be indexed > with 1 and not 0. > But that is too much to ask to change now. But that was not, what I meant to demonstrate. It would be no problem, to hand out OneBased- Indexes at the Property-Level to a consumer of such a class (by simply adding/substracting the 1 there). But then the consumers of Controls and Classes are usually developers themselfes (so, the zerobased handling would again make sense, also in the Interface-usage of such Developer-Components). What I simply meant was, that Zero-based indexing (or general zerobased-OffsetHandling) matches perfectly with (integer) math-operations - without forcing you, to include extra-adding/substracting with respects to "unnatural" onebased-offsets or indexes "every now and then" in most of your "inner routines" which "implement something". Olaf |