Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9525 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2011-07-15 18:06 +1000 |
| Last post | 2011-07-19 19:08 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-07-15 18:06 +1000 |
| Subject | Re: Python ++ Operator? |
| Message-ID | <mailman.1057.1310717193.1164.python-list@python.org> |
2011/7/15 Björn Lindqvist <bjourne@gmail.com>: > Pre and post-increments are > almost always confusing unless they are used as the counter-variable > inside for-loops. I agree that they're often confusing (i+++++j) but there are several places where they're handy. array[count++]=value; or the more direct pointer management: *ptr++=value; However, Python doesn't work as close to the bare metal, so it doesn't have such constructs. ChrisA
[toc] | [next] | [standalone]
| From | Chris Torek <nospam@torek.net> |
|---|---|
| Date | 2011-07-19 19:08 +0000 |
| Message-ID | <j04kmp02cnc@news2.newsguy.com> |
| In reply to | #9525 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web