[rust-dev] PSA: ~"string" is probably not what you want

Jack Moffitt jack at metajack.im
Sun Apr 28 14:13:26 PDT 2013


> Really?  Strings can't just be compared with == ?  To be honest, that alone
> is almost enough to put me off the language -- not only is it ugly and
> unwieldy, but it suggests a lot of limitations in the language's memory
> model / type system / operator overloading, which would also make my own
> code ugly and unwieldy.

This kind of faux outrage isn't really constructive.

Most systems languages don't let you compare strings with ==. In C you
use str*cmp as == is pointer equality. This is also true in Java where
you must write `if (foo.equals(bar))`. It would certainly be nice to
follow in C++'s footsteps where std::strings are comparable with ==,
but I'm not sure it nullifies Rust's goals if this condition can't be
met.

Equality always seems to  be a mixed bag. In JavaScript you have ==
and ===. In Erlang you have == and =:=. In Java you have == and
.equals(). In Clojure you have = and ==. Lisps have all kinds of
things. In many cases you can end up with asymmetry that violates
people's mathemeatical expectations of equality (Clojure's == is only
commutative when used with two args, with 3 it gets slightly weird).

jack.


More information about the Rust-dev mailing list