[Tutor] Not Really Questions

w chun wescpy at gmail.com
Mon Jun 5 07:29:12 CEST 2006


hi john,

everyone else has posted great replies to your inquiries, so i'll keep
mine brief.

> 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.

my 1st comment is that you are not talking about Python alone.
everything you state pertains to most other programming languages.


> 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.

sequences, arrays, etc., in most other languages do start at zero, and
have a strong tie to that addressing stuff that's already been
mentioned.  this is just a fact of programming.

> 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 is partially due to your 1st issue, that things start at zero.  a
sequence of length 5, for example, or range(5) means: 0, 1, 2, 3, 4.
even tho the counting is up to 4, you will see that this is a
collection of five items.

this feature of "i up-to-but-not-including j" also mirrors other
languages, say counting in C for example: for (i = 0; i < 5; i++);


> The 3rd whinge is object oriented programming.

like all programming tools, one must investigate whether it is the
right tool for the job.  if it's a simple one-off script, then probly
not; but if it is a huge framework where you want to most code reuse,
least amount of code to maintain, minimization of the number of bugs,
and being able to lump functionality/logic with data, OOP is the way
to go.

a simple example would be shapes and functions like finding an area.
like objects can share the same functions (called "methods"), i.e.
square.area(), rectangle.area(), whereas for other objects that aren't
similar, i wouldn't want the wrong functionality but i *would* want to
use the same name, circle.area().

the good news, as others have mentioned, is that Python is flexible,
letting you build the application as you see fit, and not locked to
any specific paradigm except perhaps KISS.

good luck!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list