3.2 KiB
- Feature Name:
rename_connect_to_join
- Start Date: 2015-05-02
- RFC PR: rust-lang/rfcs#1102
- Rust Issue: rust-lang/rust#26900
Summary
Rename .connect()
to .join()
in SliceConcatExt
.
Motivation
Rust has a string concatenation method named .connect()
in SliceConcatExt
.
However, this does not align with the precedents in other languages. Most
languages use .join()
for that purpose, as seen later.
This is probably because, in the ancient Rust, join
was a keyword to join a
task. However, join
retired as a keyword in 2011 with the commit
rust-lang/rust@d1857d3. While .connect()
is technically correct, the name may
not be directly inferred by the users of the mainstream languages. There was a
question about this on reddit.
The languages that use the name of join
are:
- Python: str.join
- Ruby: Array.join
- JavaScript: Array.prototype.join
- Go: strings.Join
- C#: String.Join
- Java: String.join
- Perl: join
The languages not using join
are as follows. Interestingly, they are
all functional-ish languages.
- Haskell: intercalate
- OCaml: String.concat
- F#: String.concat
Note that Rust also has .concat()
in SliceConcatExt
, which is a specialized
version of .connect()
that uses an empty string as a separator.
Another reason is that the term "join" already has similar usage in the standard
library. There are std::path::Path::join
and std::env::join_paths
which are
used to join the paths.
Detailed design
While the SliceConcatExt
trait is unstable, the .connect()
method itself is
marked as stable. So we need to:
- Deprecate the
.connect()
method. - Add the
.join()
method.
Or, if we are to achieve the instability guarantee, we may remove the old method entirely, as it's still pre-1.0. However, the author considers that this may require even more consensus.
Drawbacks
Having a deprecated method in a newborn language is not pretty.
If we do remove the .connect()
method, the language becomes pretty again, but
it breaks the stability guarantee at the same time.
Alternatives
Keep the status quo. Improving searchability in the docs will help newcomers find the appropriate method.
Unresolved questions
Are there even more clever names for the method? How about .homura()
, or
.madoka()
?