Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9915
| From | Chris Torek <nospam@torek.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Python ++ Operator? |
| Date | 2011-07-19 19:08 +0000 |
| Organization | None of the Above |
| Message-ID | <j04kmp02cnc@news2.newsguy.com> (permalink) |
| References | <CAH+GN=3PDVnzEp7PJZk7y9BH=vbbsPs7UJoyRcJO3o2wCg-iag@mail.gmail.com> <CALG+76dizm12CbpOAzoC7U8x6N0OH3gfBR1OjgeLtDcgJ9y50w@mail.gmail.com> <mailman.1057.1310717193.1164.python-list@python.org> |
In article <mailman.1057.1310717193.1164.python-list@python.org>
Chris Angelico <rosuav@gmail.com> wrote:
>I agree that [C's ++ operators are] often confusing (i+++++j) ...
For what it is worth, this has to be written as:
i++ + ++j /* or i+++ ++j */
or similar (e.g., newline after the middle "+" operator) as the
lexer will group adjacent "++" characters into a single "++" operator
whenever it can (the so-called "greedy matching" that regular
expression recognizers are famous for), and only later will the
parser and semantic analysis phases realize that "i++ ++ +j" is
invalid and complain.
>but there are several places where they're handy. ...
>However, Python doesn't work as close to the bare metal, so it
>doesn't have such constructs.
More specifically, Python has appropriate higher-level constructs
that, in effect, maintain "mental invariants" in a better (for some
value of better) way. Instead of:
lst[i++] = val; /* or: *p++ = val; */
which has the effect of appending an item to an array-based list
of items -- the "invariant" here is that i (or p in the pointer
version) always tells you where the place the *next* item -- one
simply writes:
lst.append(val)
(which also makes sure that there is *room* in the array-based
list, something that requires a separate step in C).
--
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Python ++ Operator? Chris Angelico <rosuav@gmail.com> - 2011-07-15 18:06 +1000 Re: Python ++ Operator? Chris Torek <nospam@torek.net> - 2011-07-19 19:08 +0000
csiph-web