[Edu-sig] indexing, slicing (was : the state of the link)

denis denis.spir at free.fr
Wed Apr 21 06:35:15 EDT 2004


Hello David & all,

Thank you for your answer.

I know both of index bases, too, having programmed in C, Pascal,... (by the
way, the expression "off-by-one errors" is particuliarly famous among
programmers of the C-family language, I guess)
Finally, the previous text could have been much shorter :
I just wanted to point out the fact that, when reading l[3], any
not-programmer would spontaneously (intuitively ?) guess that 3 is the
ordinal 'number 3', in other words that this expression means "the third
item of l", not "the second one". If ever that person doesn't get this at
once, he or she will understand it, when told, with no need of any farther
explaination.
The same for l[2 to 4].
Why ? Is this "natural" ? It doesn't mind, anyway. This issue always yields
endless talks between programmers or beginners, isn't it a relevant symptom
of its "faultyness" ?  These expressions seem to mean that ; this sense
matches the reality -- or at least our reality (even when glueing
subsequences, as shown in the longer message). If ever a piece of code
*does* something (let's take it for granted...) and *means* something (= is
not obscurely unreadable), then this meaning and the task performed should
match, nom d'une pipe (french idiom) ! In one word : the code should tell
what it does, not what it doesn't.

That long message was finally only that long, because i tried to answer
numerous and complicated counter-arguments to the opinion more quickly
(correct ? or quicklier ?) expressed above.

On the other hand, I would be very receptive to relevant advantages of a way
of extracting items out of a set, say, with 0-based index and half-open
interval. After all, the purpose is not to torture programmers instead of
beginners. If so, we should find a smart syntax / vocabulary to express it
in a non ambiguous, not error-leading, way ; and, yes, accept that newbies
have to pass through an uneasy stage before they master it -- because the
future advantages are worth it !
Sure, Dijksrtra is certainly right and I, wrong. But I would be happy to
agree with him because his arguments convince me, not because he was a
clever & wise computer scientist, while I'm not even a professionnal
programmer. I read him carefully and was astonished by the contrast between
his argumentation and such a quote :

"I mean, if 10 years from now, when you are doing something quick and dirty,
you suddenly visualize that I am looking over your shoulders and say to
yourself: 'Dijkstra would not have liked this', well that would be enough
immortality for me."

He often supports better code against superficial efficiency, his aim was
obviously not toclose programmers up in esoteric rules -- excluding at the
same time the rest of the world from the noble & zen art of programming. But
his text on slicing lets me cold (french idiom) and, even if right and fair,
seems to point particuliar and rare cases. (I personly seldom found
advantages of the kinds he points.) For instance, is it common to need a
sequence (1) starting at index zero (2) empty (3) literal (4) expressed as
[0:0] instead of [0] ? Whatever the advantages, I think that if they're
really as small and rare as they seem to me, then the readibility issue
weighs infinitly more.

denis

PS : I realise how much I wrote again. Sorry for that, hope you didn't read
it all if you don't really feel concerned. Anyway, I think this time I've
said all about that point...

----- Original Message -----
From: David Handy <david at handysoftware.com>
To: denis <denis.spir at free.fr>
Cc: edu-sig python <edu-sig at python.org>
Sent: Wednesday, April 21, 2004 2:34 AM
Subject: Re: [Edu-sig] the state of the link


> Yes, I noticed the email and wanted to reply to it. The problem is that I
> wanted to give you a well-worded answer, and I just couldn't come up with
> one in the short time I have.
>
> My experience is that Edgar Djikstra is right. It turns out that
> zero-based indexing with assymetric bounds is the right way to go.  I have
> tried to implement things like string parsing in a 1-based index language
> (BASIC) and in a zero-based index language (C/C++) so I know the
> difference. I was going to write up some examples of just how cumbersome
> 1-based indexing can become, but I just don't have the time for it. If you
> are skeptical then you just have try it to experience these problems
> yourself. :)
>
> On Mon, 19 Apr 2004, denis wrote:
>
> > Hello,
> >
> > Well, I sent a rather heavy message two days ago. The kind of thing, you
> > know, that may explode one's mailbox with reactions. I was wondering how
> > many tons of letters the postman would have to carry ; and in fact the
> > number (cardinal) of answer(s) is 'zero' (hehe !).
> > Thus this message as a link control tool. Did you get the parcel ?
> >
> > salutation,
> > denis
> >
> >
> >
> >
> > _______________________________________________
> > Edu-sig mailing list
> > Edu-sig at python.org
> > http://mail.python.org/mailman/listinfo/edu-sig
> >
>
>







More information about the Edu-sig mailing list