| Store | Cart

Grouping code by indentation - feature or ******?

From: Jacob Lee <jel...@uiuc.edu>
Sun, 27 Mar 2005 01:00:34 -0600
On Sat, 26 Mar 2005 10:02:13 +0100, Javier Bezos wrote:

> > "Tim Tyler" <tim at .org> escribi? en el mensaje> news:IDwEr6.K2u at bath.ac.uk...>> What do you guys think about Python's grouping of code via indentation?>>>> Is it good - perhaps because it saves space and eliminates keypresses?>>>> Or is it bad - perhaps because it makes program flow dependent on>> invisible, and unpronouncable characters - and results in more>> manual alignment issues by preventing code formatters from managing>> indentation?> > I particularly hate it, but Python has lots of good> things which compesate that (another annoying point> of Python are slices -- mine are always off by 1).> I always write explicitly ends as #end, so that I> can reorganice the code easily if necessary. Maybe> in the future, when Ruby matures, I could change> my mind, but currently Python is still my favourite> scripting language (as formerly was Tcl).> 

About slices:

I agree that Python's slice boundaries (some_list[a:b] being all elements
with a <= index < b) are counterintuitive at first. But this method does
satisfy some handy properties, the first of which being:
  l[:n] + l[n:] = l
Secondly, the range() function behaves identically to slices, meaning that
  for i in range(10):
will iterate 10 times, and
  for i in range(len(l)):
will iterate over the indices of the sequence l.

If you had l[a:b] be inclusive on both a and b (instead of inclusive on a
and exclusive on b), you would have to be adding and subtracting one in
all of these examples, leading that much more easily to off-by-one errors.

A digression: my data structures teacher (in c++) has a vector class that
allows you to set upper and lower bounds, and he combines this with for
loops that usually start at one but don't always. I doubt he was trying to
get this point across, but the lesson I've learned is to always start at
zero and count to less than the length of the list (in c, the idiom is
for (i = 0; i < length; i++)). Believe me that any other way will only
lead to trouble! :-)

-- 
Jacob Lee
jelee2 at uiuc.edu | www.nearestneighbor.net

Recent Messages in this Thread
Tim Tyler Mar 25, 2005 08:11 am
Peter Otten Mar 25, 2005 08:48 am
Skip Montanaro Mar 25, 2005 12:52 pm
Tim Tyler Mar 26, 2005 03:30 pm
Antoon Pardon Mar 25, 2005 12:56 pm
John Roth Mar 25, 2005 01:22 pm
Antoon Pardon Mar 25, 2005 02:26 pm
Antoon Pardon Mar 29, 2005 07:57 am
Antoon Pardon Mar 29, 2005 07:47 am
Roy Smith Mar 29, 2005 01:35 pm
Kent Johnson Mar 25, 2005 01:51 pm
Carl Banks Mar 25, 2005 02:15 pm
Antoon Pardon Mar 25, 2005 02:41 pm
Diez B. Roggisch Mar 25, 2005 03:02 pm
Antoon Pardon Mar 25, 2005 03:16 pm
Diez B. Roggisch Mar 25, 2005 03:33 pm
Antoon Pardon Mar 29, 2005 07:34 am
Diez B. Roggisch Mar 29, 2005 09:43 pm
Rocco Moretti Mar 25, 2005 05:21 pm
Tim Roberts Mar 26, 2005 09:03 am
Peter Otten Mar 26, 2005 10:29 am
Kent Johnson Mar 26, 2005 12:09 pm
Skip Montanaro Mar 26, 2005 12:41 pm
Peter Otten Mar 26, 2005 07:02 pm
Kent Johnson Mar 27, 2005 02:43 am
Peter Otten Mar 27, 2005 05:42 am
Reinhold Birkenfeld Mar 27, 2005 05:08 pm
projecktzero Mar 25, 2005 02:43 pm
Larry Bates Mar 25, 2005 04:15 pm
Ivan Van Laningham Mar 25, 2005 04:39 pm
James Stroud Mar 25, 2005 07:31 pm
Robert Kern Mar 25, 2005 07:38 pm
Bill Mill Mar 25, 2005 07:47 pm
Larry Bates Mar 25, 2005 09:56 pm
Jeremy Bowers Mar 26, 2005 05:50 am
Ron_Adam Mar 26, 2005 05:36 pm
Mike Meyer Mar 26, 2005 10:52 pm
Terry Reedy Mar 25, 2005 06:42 pm
Paul McGuire Mar 26, 2005 06:13 am
Javier Bezos Mar 26, 2005 09:02 am
Tim Tyler Mar 26, 2005 03:42 pm
Jeremy Bowers Mar 26, 2005 11:17 am
Jacob Lee Mar 27, 2005 07:00 am
Javier Bezos Mar 27, 2005 03:30 pm
Reinhold Birkenfeld Mar 27, 2005 05:11 pm
Javier Bezos Mar 27, 2005 06:04 pm
Myles Strous Mar 30, 2005 06:08 am
Myles Strous Mar 30, 2005 06:13 am
Javier Bezos Mar 30, 2005 06:00 pm
Greg Ewing Apr 01, 2005 06:05 am
Javier Bezos Mar 28, 2005 06:05 pm
Reinhold Birkenfeld Mar 27, 2005 05:10 pm
Scott David Daniels Mar 27, 2005 09:41 pm
Terry Reedy Mar 30, 2005 01:55 am
Tim Roberts Mar 30, 2005 06:48 am
James Stroud Mar 26, 2005 11:36 pm
Terry Reedy Mar 25, 2005 06:41 pm
Messages in this thread