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

Inconsistent parameter name "capacity" #60271

Closed
mgeier opened this issue Apr 25, 2019 · 3 comments
Closed

Inconsistent parameter name "capacity" #60271

mgeier opened this issue Apr 25, 2019 · 3 comments
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@mgeier
Copy link
Contributor

mgeier commented Apr 25, 2019

I've been told that parameter names are not part of the API, so this might not matter at all (except to pedantic people like me):

I've found 17 functions with the name with_capacity(): https://doc.rust-lang.org/stable/std/index.html?search=with_capacity

Most of them use capacity as parameter name:

  1. https://doc.rust-lang.org/alloc/vec/struct.Vec.html#method.with_capacity
  2. https://doc.rust-lang.org/std/vec/struct.Vec.html#method.with_capacity
  3. https://doc.rust-lang.org/alloc/string/struct.String.html#method.with_capacity
  4. https://doc.rust-lang.org/std/string/struct.String.html#method.with_capacity
  5. https://doc.rust-lang.org/alloc/collections/binary_heap/struct.BinaryHeap.html#method.with_capacity
  6. https://doc.rust-lang.org/std/collections/binary_heap/struct.BinaryHeap.html#method.with_capacity
  7. https://doc.rust-lang.org/std/collections/struct.HashSet.html#method.with_capacity
  8. https://doc.rust-lang.org/std/collections/struct.HashSet.html#method.with_capacity_and_hasher
  9. https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.with_capacity
  10. https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.with_capacity_and_hasher
  11. https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.with_capacity
  12. https://doc.rust-lang.org/std/ffi/struct.OsString.html#method.with_capacity

Some functions, however, use cap as argument name:

  1. https://doc.rust-lang.org/std/io/struct.LineWriter.html#method.with_capacity
  2. https://doc.rust-lang.org/std/io/struct.BufWriter.html#method.with_capacity
  3. https://doc.rust-lang.org/std/io/struct.BufReader.html#method.with_capacity

Others are using n:

  1. https://doc.rust-lang.org/alloc/collections/vec_deque/struct.VecDeque.html#method.with_capacity
  2. https://doc.rust-lang.org/std/collections/vec_deque/struct.VecDeque.html#method.with_capacity

Wouldn't it make sense to call all of them capacity?

Does anyone care about such things?

If yes, we could play the same game with swap() and probably with other common functions.

@jonas-schievink jonas-schievink added C-cleanup Category: PRs that clean code up or issues documenting cleanup. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Apr 25, 2019
@estebank
Copy link
Contributor

Parameter names are not part of the API because arguments in Rust are always only positional, which means that changing the name is never a breaking change. This means that we both don't care to change it nor to keep it as is ^_^

I think this is for T-libs/T-docs to decide.

@nagisa
Copy link
Member

nagisa commented Apr 25, 2019

I encourage you to post a PR which unifies the names. They appear in the documentation, so this is essentially a documentation improvement, and those are generally well accepted.

@mgeier
Copy link
Contributor Author

mgeier commented Apr 26, 2019

I encourage you to post a PR which unifies the names.

Done: #60316

Centril added a commit to Centril/rust that referenced this issue Apr 27, 2019
…=joshtriplett

Use "capacity" as parameter name in with_capacity() methods

See rust-lang#60271.

The only place where I didn't change the parameter name is `RawVec`. The problem is that it has a `.cap()` method instead of the usual `.capacity()`:

https://github.com/rust-lang/rust/blob/597f432489f12a3f33419daa039ccef11a12c4fd/src/liballoc/raw_vec.rs#L200-L210

Changing this would be a breaking change, and I guess that's not worth it.

But since I didn't change `.cap()` there, I didn't change the `cap` parameter name to `capacity`, either.
Centril added a commit to Centril/rust that referenced this issue Apr 27, 2019
…=joshtriplett

Use "capacity" as parameter name in with_capacity() methods

See rust-lang#60271.

The only place where I didn't change the parameter name is `RawVec`. The problem is that it has a `.cap()` method instead of the usual `.capacity()`:

https://github.com/rust-lang/rust/blob/597f432489f12a3f33419daa039ccef11a12c4fd/src/liballoc/raw_vec.rs#L200-L210

Changing this would be a breaking change, and I guess that's not worth it.

But since I didn't change `.cap()` there, I didn't change the `cap` parameter name to `capacity`, either.
Centril added a commit to Centril/rust that referenced this issue Apr 27, 2019
…=joshtriplett

Use "capacity" as parameter name in with_capacity() methods

See rust-lang#60271.

The only place where I didn't change the parameter name is `RawVec`. The problem is that it has a `.cap()` method instead of the usual `.capacity()`:

https://github.com/rust-lang/rust/blob/597f432489f12a3f33419daa039ccef11a12c4fd/src/liballoc/raw_vec.rs#L200-L210

Changing this would be a breaking change, and I guess that's not worth it.

But since I didn't change `.cap()` there, I didn't change the `cap` parameter name to `capacity`, either.
@bors bors closed this as completed in be12ab0 Apr 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants