Rant after trying Rust a bit
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Sun Aug 2 14:17:08 PDT 2015
On Sunday, 2 August 2015 at 19:02:22 UTC, Max Samukha wrote:
> On Sunday, 26 July 2015 at 23:29:18 UTC, Walter Bright wrote:
>
>> For example, the '+' operator. Rust traits sez "gee, there's a
>> + operator, it's good to go. Ship it!" Meanwhile, you thought
>> the function was summing some data, when it actually is
>> creating a giant string, or whatever idiot thing someone
>> decided to use '+' for.
>
> Number addition and string concatenation are monoid operations.
> In this light, '+' for both makes perfect sense.
Well, using + for "adding" strings together does make sense on
some level, which is why it's done in so many languages, and I
don't think that it causes as much confusion as Walter sometimes
seems to think (at least in C/C++-derived languages). That being
said, I think that it's definitely an improvement that D has
another operator for it. It makes it clearer when concatenation
is occurring without having to figure out what types you're
dealing with, and it allows user-defined code to have both an
addition operator and a concatenation operator on the same type.
Where distinguishing between + and ~ would likely make a big
difference though is dynamic languages that aren't strict with
types and allow nonsense like "5" + 2. And in that case, I expect
that Walter is completely right. It's just error-prone to use +
for concatenation in cases like that, and providing a separate
concatenation operator would reduce bugs.
Regardless, I definitely like the fact that we have ~ and ~=
instead of reusing + and += for that. It's a small improvement,
but it is an improvement.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list