Also in Python you can use:

for x in range (1,j+1):


to loop j times. Although it does read as though it is looping j+1 times to those not familiar.


One more comment I wanted to make about end blocks, is that a respectable editor will add them for you, together with the indentation of the next line. EditPlus 2 did it best in my experience although I think I just haven't seen a well configured alternative. I very rarely forget the block closer but I do sometimes forget the colon.


Regarding the logical inconsistency of my argument, well I am saying that I would prefer my redundancy at the end of the loop rather than the beginning. To say that the status quo is better is to say that you prefer your redundancy at the beginning. Fair enough, I'm happy to respect your opinion there. I still struggle to see why it should be mandatory though? For those who prefer to have the block closing delimiters this way, is the need for a keyword (could be a command line option) really the objection?


I'll have a detailed look at your colon link a bit later.


On 10/01/17 09:26, Chris Barker wrote:
On Mon, Jan 9, 2017 at 5:12 PM, Simon Lovell <simon58...@bigpond.com <mailto: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 <mailto:Python-ideas@python.org>
    https://mail.python.org/mailman/listinfo/python-ideas
    <https://mail.python.org/mailman/listinfo/python-ideas>
    Code of Conduct: http://python.org/psf/codeofconduct/
    <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 <mailto: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/

Reply via email to