Skip to content
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

refactor(vim.iter)!: rename xxback() => rxx() #28503

Merged
merged 1 commit into from Apr 26, 2024
Merged

Conversation

justinmk
Copy link
Member

@justinmk justinmk commented Apr 25, 2024

Open questions

  • instead of renaming xxback => rxx, could remove xxback and let the various functions accept negative indexes. The tradeoff is that it's a bit less obvious that the negative indexes are only supported for list-iterators. With rxx(), it's easy to notice that "the rxx functions only accept list-iterators".

Problem:

vim.iter has both rfind() and various *back() methods, which work in "reverse" or "backwards" order. It's inconsistent to have both kinds of names, and "back" is fairly uncommon (rust) compared to python (rfind, rstrip, rsplit, …). #27953

Solution:

  • Remove nthback() and let nth() take a negative index.
    • Because rnth() looks pretty obscure, and because it's intuitive for a function named nth() to take negative indexes.
  • Rename xxback() methods to rxx().
    • Bonus: this groups the "list-iterator" functions under a common r prefix.
  • Rename peekback() to pop().
    • pop is chosen in duality with the existing peek.

Alternatives

We could remove the xxback() functions and instead let the xx() variants accept negative indexes. That has some tradeoffs:

  • complicates documentation a bit, because the "reverse" variants are only supported for list-like iterator (:help list-iterator)
  • the "r" prefix has the small benefit of grouping the "family" of "reverse" functions.

closes #27953

@github-actions github-actions bot added refactor changes that are not features or bugfixes breaking-change labels Apr 25, 2024
Problem:
vim.iter has both `rfind()` and various `*back()` methods, which work
in "reverse" or "backwards" order. It's inconsistent to have both kinds
of names, and "back" is fairly uncommon (rust) compared to python
(rfind, rstrip, rsplit, …).

Solution:
- Remove `nthback()` and let `nth()` take a negative index.
  - Because `rnth()` looks pretty obscure, and because it's intuitive
    for a function named `nth()` to take negative indexes.
- Rename `xxback()` methods to `rxx()`.
  - This informally groups the "list-iterator" functions under a common
    `r` prefix, which helps discoverability.
- Rename `peekback()` to `pop()`, in duality with the existing `peek`.
@justinmk justinmk merged commit 9b028bd into neovim:master Apr 26, 2024
29 checks passed
@justinmk justinmk deleted the iter branch April 26, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change refactor changes that are not features or bugfixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vim.iter: rename some functions before 0.10 release
1 participant