On Mon, Jan 9, 2017 at 5:12 PM, Simon Lovell <simon58...@bigpond.com> wrote:
> Re: Counters starting at zero vs one, Fortran has a neat solution to this > for arrays if not strings - allow the programmer to select the starting > index. I liked that back in the day, but I think it's really better if it's always the same. and see my other note for why the zero-based and open ended slicing is fabulous -- indexing really needs to match slicing. ONe more: since you mentioned Fortran -- it's a common use-case for an array to model some sort of regular spaced grid, so: x = start_x + i*delta_x really easy and logical math for figuring out where you are on a grid (and the reverse calculation) -- this is a pain with 1-based indexing.... (of course, C does this for pointer math for the same reason...) When I've programmed for loops in C, sometimes you want zero based and > sometimes one based, while most times you don't really care. To make it > readable I would wherever possible write either: > for (i=0;i<j;i++) > for (i=1;i<=j;i++) // In both cases always executing j times > in pyton, you never right that code anyway. most of the time, it's for item in sequence: no indexes at all. or: for i in range(N): ... indexes, but you dont care or for i, item in enumerate(seq): ... or for item1, item2 in zip(sequence): ... i.e you almost never care what the starting index is! -CHB > Rgds > > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/