In some contexts, specifically adding a +
in front of a numeric literals can enhance readability and given that -1.0
is a valid syntax, +1.0
should be also.
My opinion: More complexity, bikeshedding needed, so I’m against it.
Here’s the bikeshed you ordered
-
Do we support unary-plus for general expressions:
+expr;
? -
Can it be allowed on non-numbers:
+"string"
? -
How about
+BigInt::new("3")
? -
Can unary-plus be overloaded?
trait Pos { type Result; fn pos(self) -> Self::Result; }
-
Or should it just be a sugar for “no-op”?
-
Should Pos just be a marker trait if we don’t want
+"string"
to be valid? -
What should be the name of this trait, if it is needed?
I’ve never seen an unary + in school-math, college-math or later math. I don’t see how it would be more readable. If you are worried about alignment, make an rfc for the style guide to add spaces to align numbers.
I would vote for sugar for no-op. Just for “mathematical” consistency.
frequently used for quantities that are sometimes positive and sometimes negative like charge
but can this create ambiguities in the future?
I think the main reason for adding this is because all the other programming languages support it. The syntax would just be a +
before a number where ever a -
is allowed.
However, rust hasn’t been into the trend of “doing things because other people do them”, so I’m not sure we need this.
A completely different idea for the use of a unary plus in a language...
Once upon a time I made a programming language named Reia:
I eventually got quite emo about it after realizing that making a programming language is really hard and that the language I created really wasn't the one I wanted to use.
Circa 2011 I wrote up my notes about what I'd like the next language I designed (probably not going to happen, thanks Rust!) to look like:
In it I proposed the otherwise useless unary + operator as bestowing a particular capability on its operand, specifically in the case of literals it made them mutable.
I'm not saying that's a good idea for Rust, but before you consider making unary "+" a useless operation simply because that's what all the other languages are doing, perhaps think about whether you could use it in a useful way.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.