[Tutor] Not Really Questions

Kent Johnson kent37 at tds.net
Sun Jun 4 20:05:08 CEST 2006


John Connors wrote:
> G'day,
> 
> While the list is kind of slow I thought I'd post a few thoughts on a couple 
> of things in Python that bug me. They're not really questions but maybe 
> someone can help me understand.

Maybe I can give you some not-really answers ;)
> 
> The first one is lists... I can't for the life of me understand why a list 
> starts at zero. In everything else in life other than programming the 1st 
> item in a list is always 1.

Many programming languages start indexes at zero. It makes sense if you 
think of a list being stored as sequential values in memory, and the 
index as the offset from the start of the list. (This is in fact how 
arrays are often implemented.)
> 
> The next thing I don't understand is why the last number in a range is not 
> used...
> 
> For a in range(1,6):
>     print a,
> 
> 1 2 3 4 5
> 
> Once again it defies the logic of everything else we are taught in life.

This actually prevents many types of errors. Alex Martelli has a good 
explanation here (also see his other posts in the same thread):
http://groups.google.com/group/comp.lang.python/msg/579b53de640190cd

> 
> The 3rd whinge is object oriented programming. I think I understand the 
> principle behind OOP but in practise, to me, it just makes programs jumbled, 
> unreadable and bloated. Just about every summary I have read on Python says 
> it is designed to have a simple syntax and is easy to learn. As a beginner I 
> can look at Python code and have a very good idea of what is happening and 
> why unless it's written in OOP style in which case I have no idea.

OOP does take some getting used to, it is a different way of thinking 
about the structure of a program. Done badly, it is a good way to make a 
mess. Done well, it is a tool for creating a highly modular program 
where the responsibilities of each piece are well defined.

Kent



More information about the Tutor mailing list