Re: Baby X is bor nagain

Liste des GroupesRevenir à cl c  
Sujet : Re: Baby X is bor nagain
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.c
Date : 21. Jun 2024, 10:02:49
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v53c39$320dd$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 21/06/2024 00:40, bart wrote:

During the last 20 or more years, Python implementations have gotten more and more efficient. So if there is a difference between range and xrange, there are techniques that can be used to minimise it.
Yes.  Like most languages (except assembly, Forth, and perhaps a few other very low-level languages) Python is defined in terms of its effects, not specific implementations of its features.  The effect of generating a list of consecutive integers then iterating over it, and of generating a C for style loop, are the same - but obviously the run-time efficiency will typically be very different.
Python is not a language with much optimisation in itself - but the compiler (byte-compiler) has got more sophisticated over time.  Common use-cases of range where the list nature of the range is not important, have been improved - modern Python does not generate a list for ranges unless they are actually necessary.
Conceptually, having ranges as a list is very nice.  It is a design choice geared towards ease of use, consistency and functionality, rather than ease of efficient implementation.  Like functional programming languages, it's a design that appeals to people thinking mathematically or with high-level concepts in mind, but it will seem alien and inefficient to people thinking from the low level up or considering implementation details.
Your programming experience has mainly been through assembly, low-level languages, and implementation of your own fairly low-level languages.  I expect that whenever you see code in any language, part of your mind is automatically trying to think of how you could implement that in a code generator.  So when you see something like Python's "range" expression, you immediately see the obvious implementation, and that this is clearly a highly inefficient way to get a simple for-loop.
I too have a background in assembly - even lower, in fact, since I work with electronics and am also familiar with logic design and the basic principles of processor design.  But I also have a background in mathematics, and as well as assembly and C, I have worked with functional programming languages and other high-level languages.  To me, there is nothing wrong with using recursive functions over infinite lists as a way of making a loop - /if/ the language supports it reasonably efficiently.  And there is nothing wrong with a language that is 1000 times slower to run but 10 times faster to code.

 But if should never have been done that crazy way in the first place.
 However if I compare range to xrange now on Py2 using such loops as your examples, then xrange is about twice as fast. But range on Py3 is in-between. Basically I've no idea what's going on inside it these days.
xrange always gives you a structure that is a kind of iterator or generator - it holds a start value, end value, step value and current value.  It is not a list, and does not have the same types of methods as a list.  For example, you can't modify it.
In Python3, range() actually returns an range object, which is basically a rename of the Python2 xrange object.  To get the old behaviour of range() as a list, you now need to write "list(range(100))".
A major point, however, is that for the most part, you don't need to know what is going on inside it.  I know you like to understand these things (I do too), and it's hard to turn off the curiosity instincts. But at least understand that for the vast majority of other users, the underlying details don't matter.  Their Python "for" loops are faster than they used to be, and that's nice - why bother about the hidden details when there are other things to occupy one's time and brainpower?

Date Sujet#  Auteur
11 Jun 24 * Baby X is bor nagain322Malcolm McLean
11 Jun 24 +* Re: Baby X is bor nagain3bart
11 Jun 24 i`* Re: Baby X is bor nagain2Malcolm McLean
12 Jun 24 i `- Mac users (Was: Baby X is bor nagain)1Kenny McCormack
11 Jun 24 +* Re: Baby X is bor nagain4Ben Bacarisse
11 Jun 24 i`* Re: Baby X is bor nagain3Malcolm McLean
12 Jun 24 i `* Re: Baby X is bor nagain2Ben Bacarisse
12 Jun 24 i  `- Re: Baby X is bor nagain1Malcolm McLean
11 Jun 24 +* Re: Baby X is bor nagain313Bonita Montero
11 Jun 24 i+* Re: Baby X is bor nagain309Malcolm McLean
12 Jun 24 ii`* Re: Baby X is bor nagain308Bonita Montero
12 Jun 24 ii +* Re: Baby X is bor nagain305David Brown
12 Jun 24 ii i+* Re: Baby X is bor nagain2Malcolm McLean
12 Jun 24 ii ii`- Re: Baby X is bor nagain1David Brown
12 Jun 24 ii i+- Re: Baby X is bor nagain1Bonita Montero
12 Jun 24 ii i`* Re: Baby X is bor nagain301bart
12 Jun 24 ii i +* Re: Baby X is bor nagain4Bonita Montero
12 Jun 24 ii i i`* Re: Baby X is bor nagain3bart
12 Jun 24 ii i i `* Re: Baby X is bor nagain2Bonita Montero
12 Jun 24 ii i i  `- Re: Baby X is bor nagain1bart
12 Jun 24 ii i `* Re: Baby X is bor nagain296David Brown
12 Jun 24 ii i  `* Re: Baby X is bor nagain295Michael S
13 Jun 24 ii i   +- Re: Baby X is bor nagain1Malcolm McLean
13 Jun 24 ii i   `* Re: Baby X is bor nagain293David Brown
13 Jun 24 ii i    +* Re: Baby X is bor nagain5bart
13 Jun 24 ii i    i+* Re: Baby X is bor nagain3tTh
13 Jun 24 ii i    ii`* Re: Baby X is bor nagain2bart
14 Jun 24 ii i    ii `- Re: Baby X is bor nagain1Bonita Montero
13 Jun 24 ii i    i`- Re: Baby X is bor nagain1Michael S
13 Jun 24 ii i    `* Re: Baby X is bor nagain287Michael S
14 Jun 24 ii i     +* Re: Baby X is bor nagain3David Brown
14 Jun 24 ii i     i`* Re: Baby X is bor nagain2bart
15 Jun 24 ii i     i `- Re: Baby X is bor nagain1David Brown
17 Jun 24 ii i     `* Re: Baby X is bor nagain283James Kuyper
17 Jun 24 ii i      +* Re: Baby X is bor nagain86Kaz Kylheku
17 Jun 24 ii i      i+- Are Javascript and Python similarly slow ? (Was: Baby X is bor nagain)1Michael S
17 Jun 24 ii i      i+* Re: Baby X is bor nagain2Michael S
18 Jun 24 ii i      ii`- Re: Baby X is bor nagain1Tim Rentsch
17 Jun 24 ii i      i+* Re: Baby X is bor nagain80David Brown
18 Jun 24 ii i      ii`* Re: Baby X is bor nagain79Michael S
18 Jun 24 ii i      ii `* Re: Baby X is bor nagain78David Brown
18 Jun 24 ii i      ii  +* Re: Baby X is bor nagain7bart
18 Jun 24 ii i      ii  i`* Re: Baby X is bor nagain6David Brown
18 Jun 24 ii i      ii  i +* Re: Baby X is bor nagain2bart
18 Jun 24 ii i      ii  i i`- Re: Baby X is bor nagain1David Brown
18 Jun 24 ii i      ii  i `* Re: Baby X is bor nagain3DFS
18 Jun 24 ii i      ii  i  `* Re: Baby X is bor nagain2Mark Bourne
18 Jun 24 ii i      ii  i   `- Re: Baby X is bor nagain1DFS
18 Jun 24 ii i      ii  +* Re: Baby X is bor nagain3Malcolm McLean
18 Jun 24 ii i      ii  i+- Re: Baby X is bor nagain1David Brown
18 Jun 24 ii i      ii  i`- Re: Baby X is bor nagain1Mark Bourne
18 Jun 24 ii i      ii  `* Re: Baby X is bor nagain67Michael S
18 Jun 24 ii i      ii   +* Re: Baby X is bor nagain65Malcolm McLean
19 Jun 24 ii i      ii   i+* Re: Baby X is bor nagain59Keith Thompson
19 Jun 24 ii i      ii   ii`* Re: Baby X is bor nagain58Malcolm McLean
19 Jun 24 ii i      ii   ii +* Re: Baby X is bor nagain56David Brown
19 Jun 24 ii i      ii   ii i`* Re: Baby X is bor nagain55Malcolm McLean
19 Jun 24 ii i      ii   ii i `* Re: Baby X is bor nagain54David Brown
19 Jun 24 ii i      ii   ii i  `* Re: Baby X is bor nagain53Malcolm McLean
19 Jun 24 ii i      ii   ii i   +* Re: Baby X is bor nagain10bart
20 Jun 24 ii i      ii   ii i   i`* Re: Baby X is bor nagain9David Brown
20 Jun 24 ii i      ii   ii i   i `* Re: Baby X is bor nagain8bart
20 Jun 24 ii i      ii   ii i   i  `* Re: Baby X is bor nagain7David Brown
20 Jun 24 ii i      ii   ii i   i   `* Re: Baby X is bor nagain6bart
20 Jun 24 ii i      ii   ii i   i    +* Re: Baby X is bor nagain2Michael S
20 Jun 24 ii i      ii   ii i   i    i`- Re: Baby X is bor nagain1bart
20 Jun 24 ii i      ii   ii i   i    `* Re: Baby X is bor nagain3David Brown
21 Jun 24 ii i      ii   ii i   i     `* Re: Baby X is bor nagain2bart
21 Jun 24 ii i      ii   ii i   i      `- Re: Baby X is bor nagain1David Brown
20 Jun 24 ii i      ii   ii i   `* Re: Baby X is bor nagain42David Brown
20 Jun 24 ii i      ii   ii i    `* Re: Baby X is bor nagain41Malcolm McLean
20 Jun 24 ii i      ii   ii i     +- Re: Baby X is bor nagain1David Brown
20 Jun 24 ii i      ii   ii i     `* Re: Baby X is bor nagain39Ben Bacarisse
20 Jun 24 ii i      ii   ii i      +* Re: Baby X is bor nagain2Malcolm McLean
20 Jun 24 ii i      ii   ii i      i`- Re: Baby X is bor nagain1Ben Bacarisse
20 Jun 24 ii i      ii   ii i      +* Re: Baby X is bor nagain9Tim Rentsch
20 Jun 24 ii i      ii   ii i      i`* Re: Baby X is bor nagain8Malcolm McLean
20 Jun 24 ii i      ii   ii i      i +* Re: Baby X is bor nagain2James Kuyper
20 Jun 24 ii i      ii   ii i      i i`- Re: Baby X is bor nagain1Keith Thompson
20 Jun 24 ii i      ii   ii i      i +- Re: Baby X is bor nagain1Vir Campestris
20 Jun 24 ii i      ii   ii i      i +* Re: Baby X is bor nagain2Keith Thompson
21 Jun 24 ii i      ii   ii i      i i`- Re: Baby X is bor nagain1vallor
21 Jun 24 ii i      ii   ii i      i +- Re: Baby X is bor nagain1Tim Rentsch
21 Jun 24 ii i      ii   ii i      i `- Re: Baby X is bor nagain1David Brown
20 Jun 24 ii i      ii   ii i      `* Re: Baby X is bor nagain27Keith Thompson
20 Jun 24 ii i      ii   ii i       `* Re: Baby X is bor nagain26Ben Bacarisse
20 Jun 24 ii i      ii   ii i        +* Re: Baby X is bor nagain2Michael S
21 Jun 24 ii i      ii   ii i        i`- Re: Baby X is bor nagain1Ben Bacarisse
20 Jun 24 ii i      ii   ii i        +- Re: Baby X is bor nagain1Keith Thompson
21 Jun 24 ii i      ii   ii i        +* Re: Baby X is bor nagain2James Kuyper
21 Jun 24 ii i      ii   ii i        i`- Re: Baby X is bor nagain1Keith Thompson
22 Jun 24 ii i      ii   ii i        `* Re: Baby X is bor nagain20Tim Rentsch
23 Jun 24 ii i      ii   ii i         `* Re: Baby X is bor nagain19Ben Bacarisse
23 Jun 24 ii i      ii   ii i          +* Re: Baby X is bor nagain9James Kuyper
23 Jun 24 ii i      ii   ii i          i`* Re: Baby X is bor nagain8Tim Rentsch
24 Jun 24 ii i      ii   ii i          i +* Re: Baby X is bor nagain4Ben Bacarisse
24 Jun 24 ii i      ii   ii i          i i`* Re: Baby X is bor nagain3Tim Rentsch
25 Jun 24 ii i      ii   ii i          i i `* Re: Baby X is bor nagain2Ben Bacarisse
25 Jun 24 ii i      ii   ii i          i i  `- Re: Baby X is bor nagain1Tim Rentsch
24 Jun 24 ii i      ii   ii i          i `* Re: Baby X is bor nagain3Keith Thompson
24 Jun 24 ii i      ii   ii i          i  `* Re: Baby X is bor nagain2Tim Rentsch
23 Jun 24 ii i      ii   ii i          `* Re: Baby X is bor nagain9Tim Rentsch
19 Jun 24 ii i      ii   ii `- Re: Baby X is bor nagain1Keith Thompson
19 Jun 24 ii i      ii   i`* Re: Baby X is bor nagain5David Brown
19 Jun 24 ii i      ii   `- Re: Baby X is bor nagain1David Brown
18 Jun 24 ii i      i+- Re: Baby X is bor nagain1James Kuyper
20 Jun 24 ii i      i`- Re: Baby X is bor nagain1Vir Campestris
17 Jun 24 ii i      +* Re: Baby X is bor nagain193bart
17 Jun 24 ii i      `* Re: Baby X is bor nagain3Malcolm McLean
12 Jun 24 ii `* Topicality is not your strong suit (Was: Baby X is bor nagain)2Kenny McCormack
11 Jun 24 i`* Re: Baby X is bor nagain3bart
11 Jun 24 `- Re: Baby X is bor nagain1Kalevi Kolttonen

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal