Hi!
> a[M:N] should _never_ produce errors because returning an empty (or
> truncated) list for a[M:N] unambiguously conveys to the programmer
> that M > len(a) (or N > len(a)).
In my opinion one has done something wrong if one wants to get a sublist
whith wrong bounds. That's why an error has to be produced. Returning an
empty list looks like everything is ok where it is not. It takes some
time to find an error if no error message is produced in such cases.
> The most common use-case for the slice operation I can think of is:
>
> for item in somelist[M:N]
> " do something
> endfor
This is a good example. M and N are not further described here. But M
and N must come from somewhere. If they are out of bounds, then in many
or even most cases the programmer has done something wrong. Even if
there may be some cases where this could make sense, it will be better
to add an if. An error is no intrusion as you call it, but a very
helpful signal that there is something wrong.
> Having a[M:N] never be an error makes the above work flawlessly.
What does 'flawlessly' mean here? Not to get an error is not good if
there is one. What may result in more harm: an additional if or writing
a good code, where your examples doesn't exist, or not producing an
error where something goes completely wrong? Therefore,
> < IMPORTANT
> Can you think of a use-case when returning an empty list will cause
> the programmer to do the "wrong thing"?
> />
is the wrong question. It is up to you to show, that not producing an
error message here won't cause the wrong thing to happen. I cannot see
that this is the case.
> Note that this and all succeeding examples are for cases when somelist
> is created dynamically, so we do not have an apriori idea of how long
> somelist is.
But somewhere you have assigned some values to M and N. That will be
done dynamically, too. If they are out of bounds, a highly probable
reason for that is, that you have done something wrong.
> IMHO python does exactly the right thing by not producing errors when
> returning a value can unambiguously convey the same information to the
> user.
And the programmers may search many hours and sometimes several days to
find errors which are covered by that. Less restricting programming
languages seem to be nice because you don't get so many error messages.
But these languages have in common, that it is very hard to find some
types of errors, which can be avoided in more restricting languages.
Best wishes,
Georg
___________________________________________________________
Switch an email account to Yahoo! Mail, you could win FIFA World Cup tickets. http://uk.mail.yahoo.com