Skip to content

Add note about pre/post increment to the design FAQ. #23186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2015

Conversation

steveklabnik
Copy link
Member

Fixes #14686

@rust-highfive
Copy link
Contributor

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@killercup
Copy link
Member

What about x += 1? Just one more character than x++ (without spaces).


## Why no `--x` or `x++`?

Pre- and post- increment, while convenient, are also fairly complex. They
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre- and post- increment

I'm not sure, but that space after "post-" looks wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I felt slightly awkward about it, but it felt more consistent. Maybe I should just re-word and write 'increment' twice

@steveklabnik
Copy link
Member Author

@killercup += has sometimes worked and sometimes not in the history of Rust, so I tend to not use it, heh.


Pre- and post- increment, while convenient, are also fairly complex. They
require knowledge of evaluation order, and often lead to subtle bugs and
undefined behavior in C and C++. `x = x + 1` and `x = x - 1` is only slightly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d go for x += 1 and x -= 1 here, because they’re both shorter and their meaning looks, at least to me, closer to the increment and decrement ops.

@steveklabnik steveklabnik force-pushed the gh14686 branch 2 times, most recently from 8ea2883 to a600899 Compare March 9, 2015 20:49
@steveklabnik
Copy link
Member Author

r? @alexcrichton

@alexcrichton
Copy link
Member

@bors: r+ a600899

@bors
Copy link
Collaborator

bors commented Mar 10, 2015

⌛ Testing commit a600899 with merge 621ccf5...

bors added a commit that referenced this pull request Mar 10, 2015
@bors bors merged commit a600899 into rust-lang:master Mar 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explain why {post,pre}-{increment,decrement} are absent in the language design FAQ.
7 participants