From: Bartc on

"D'Arcy J.M. Cain" <darcy(a)druid.net> wrote in message
news:mailman.1735.1281185722.1673.python-list(a)python.org...
> On Sat, 07 Aug 2010 13:48:32 +0200
> News123 <news1234(a)free.fr> wrote:
>> It makes sense in assembly language and even in many byte code languages.
>> It makes sense if you look at the internal representation of unsigned
>> numbers (which might become an index)
>>
>> For a complete beginner common sense dictates differently and there
>> might be confusion why the second element in a list has index 1.
>
> Would said beginner also be surprised that a newborn baby is zero years
> old or would it be more natural to call them a one year old? Zero
> based counting is perfectly natural.

Depends whether you are counting (discrete) things, or measuring them (over
a continuous range).

You would start counting at 1, but start measuring from 0.

--
Bartc


From: Bartc on
"Nobody" <nobody(a)nowhere.com> wrote in message
news:pan.2010.08.07.15.23.59.515000(a)nowhere.com...
> On Sat, 07 Aug 2010 13:48:32 +0200, News123 wrote:
>
>>> "Common sense" is wrong. There are many compelling advantages to
>>> numbering from zero instead of one:
>>>
>>> http://lambda-the-ultimate.org/node/1950
>>
>> It makes sense in assembly language and even in many byte code languages.
>> It makes sense if you look at the internal representation of unsigned
>> numbers (which might become an index)
>
> It also makes sense mathematically. E.g. for an MxN array stored as a
> 1-dimensional array, the element a[j][i] is at index
>
> j * N + i
>
> with zero-based indices but:
>
> (j-1) * N + (i-1) + 1

> = j * N + i - N
>
> with one-based indices.

In other words, an extra offset to be added, in an expression already using
a multiply and add, and which likely also needs an extra multiply and add to
get the byte address of the element.

(And often, the a[j][i] expression will be in a loop, which can be compiled
to a pointer that just steps from one element to the next using a single
add.)

The indices i and j might anyway be user data which happens to be 1-based.

And if the context is Python, I doubt whether the choice of 0-based over a
1-based makes that much difference in execution speed.

(I've implemented languages that allow both 0 and 1-based indexing (and
N-based for that matter). Both are useful. But my interpreted languages tend
to use 1-based default indexing as it seems more natural and 'obvious')

>
> IOW, if a language uses one-based indices, it will inevitably end up
> converting to and from zero-based indices under the hood,

Sometimes. At the very low level (static, fixed array), the cost is absorbed
into the address calculation. At a higher level, the cost is less
significant, or there might be tricks to avoid the extra addition.

> and may end up
> forcing the user to do likewise if they need to do their own array
> manipulation.

Lots of things require this sort of calculation, eg. how many pages are
needed to print 267 lines of text at 60 lines per page? These counts are
1-based so it's (L-1)/P+1 (integer divide), or 5 pages.

If we switch to 0-based counting, it's just L/P ('266' lines require '4'
pages), but who's going to explain that to the user?

--
Bartc


From: Jean-Michel Pichavant on
Ben Finney wrote:
> "D'Arcy J.M. Cain" <darcy(a)druid.net> writes:
>
>
>> No. You are giving me math and logic but the subject was common
>> sense.
>>
>
> Common sense is often unhelpful, and in such cases the best way to teach
> something is to plainly contradict that common sense.
>
> Common sense, for example, would have the Earth as a flat surface with
> the Sun and Moon as roughly-identically-sized objects orbiting the
> Earth. Is it better to pander to that common sense, or to vigorously
> reject it in order to teach something more useful?
>
>
I could'nt agree more. If it was not for my scolarship, I would gladly
think that the earth is flat and the sun is moving around. It took
thousands of years for *1* man to figure out that was wrong.
So if there is one thing that common sense is not helpful, then that
thing is finding the Truth.

JM

"Ignorance is the mother of all traditions" (V. Hugo)
From: D'Arcy J.M. Cain on
On Tue, 10 Aug 2010 13:51:17 +0200
Jean-Michel Pichavant <jeanmichel(a)sequans.com> wrote:

Pardon the response to the response. I missed Ben's message.

> Ben Finney wrote:
> > "D'Arcy J.M. Cain" <darcy(a)druid.net> writes:
> >> No. You are giving me math and logic but the subject was common
> >> sense.
> >
> > Common sense is often unhelpful, and in such cases the best way to teach
> > something is to plainly contradict that common sense.

I even agree with you. However, the OP was claiming that zero based
counting contradicted common sense and that was what I was responding
to. I would never use "common sense" to prove anything.

--
D'Arcy J.M. Cain <darcy(a)druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
From: Hexamorph on
Terry Reedy wrote:
> On 8/9/2010 11:16 AM, Grant Edwards wrote:

Just for the record:

I sincerely apologize for my rant. I usually don't loose control so
heavily, but this "Rick" person makes me mad (killfile'd now)

>> IOW, the "Ugly American".

No! That's not what I said. I'm myself one of those "bad germans"
and I *entirely* agree with Mr. Reedy's comment:

> Stereotypically bashing "Americans" is as ugly and obnoxious as bashing
> any other ethnic group. I have traveled the world and Americans are no
> worse, but are pretty much the same mix of good and bad. It is certainly
> off-topic and inappropriate for this group.