L
Lawrence D'Oliveiro
I wonder how many people have been tripped up by the fact that
++n
and
--n
fail silently for numeric-valued n.
++n
and
--n
fail silently for numeric-valued n.
I wonder how many people have been tripped up by the fact that
  ++n
and
  --n
fail silently for numeric-valued n.
I wonder how many people have been tripped up by the fact that
++n
and
--n
fail silently for numeric-valued n.
What do you mean, "fail silently"? They do exactly what you should
expect:
I'm not sure what "bug" you're seeing. Perhaps it's your expectations
that are buggy, not Python.
Gabriel said:En Mon, 06 Jul 2009 00:28:43 -0300, Steven D'Aprano
Well, those expectations are taken seriously when new features are
introduced into the language - and sometimes the feature is dismissed
just because it would be confusing for some.
If a += 1 works, expecting ++a to have the same meaning is very
reasonable (for those coming from languages with a ++ operator, like C
or Java) - more when ++a is a perfectly valid expression.
If this issue isn't listed under the various "Python gotchas"
articles, it should...
Well sure, it's not unreasonable to expect ++n and --n to behave as in
other languages, and since they don't, perhaps they should be listed as
a "Python gotcha". But even so, it's quite arrogant of the OP to flaunt
his ignorance of the language by claiming this is a bug and a failure.
It shouldn't have been all that hard for him to figure out what was
really happening.
In this case, a note in the documentation warning about the potential
confusion would be fine.
Tim Golden said:The difficulty here is knowing where to put such a warning.
You obviously can't put it against the "++" operator as such
because... there isn't one.
The difficulty here is knowing where to put such a warning.
You obviously can't put it against the "++" operator as such
because... there isn't one. You could put it against the unary
plus operator, but who's going to look there?
This bug is an epiphenomenon.
I wonder how many people have been tripped up by the fact that
++n
and
--n
fail silently for numeric-valued n.
Gabriel said:In this case, a note in the documentation warning about the potential
confusion would be fine.
En Mon, 06 Jul 2009 00:28:43 -0300, Steven D'Aprano
Well, those expectations are taken seriously when new features are
introduced into the language - and sometimes the feature is dismissed
just because it would be confusing for some. If a += 1 works, expecting
++a to have the same meaning is very reasonable (for those coming from
languages with a ++ operator, like C or Java) - more when ++a is a
perfectly valid expression. If this issue isn't listed under the various
"Python gotchas" articles, it should...
Terry Reedy said:How would that help someone who does not read the doc?
It obviously won't.
All it will do, is that it will enable people on this group,
who may read the manual, to tell people who complain,
to RTFM.
I agree that it would be a good idea to make it an
error, or a warning - "this might not do what you
think it does", or an "are you sure?" exception.
- Hendrik
I wonder how many people have been tripped up by the fact that
++n
and
--n
fail silently for numeric-valued n.
The fact that it isn't suggests strongly to me that it isn't that common
a surprise even for Java and C programmers. This is the first time I've
seen anyone raise it as an issue.
It obviously won't.
All it will do, is that it will enable people on this group,
who may read the manual, to tell people who complain,
to RTFM.
 I agree that it would be a good idea to make it an
error, or a warning - "this might not do what you
think it does", or an "are you sure?" exception.
Â
- Hendrik
Recent python-ideas discussion on this subject:
http://mail.python.org/pipermail/python-ideas/2009-March/003741.html
Terry said:... it is C, not Python, that is out of step with standard usage in math
and most languages ...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.