Skip to content

Inconsistent parameter name "capacity" #60271

Closed
@mgeier

Description

@mgeier

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions