0

Given that there is unary Numerical#-@, from symmetry, it might be tempting to have Numerical#+@, but my understanding is that the design philosophy of Ruby by Matz is that a feature would not be added just for symmetry, but has to have a practical use case.

If the unary Numerical#+@ were left for user to define freely, that might have been useful. But I cannot think of any use case of it as is pre-defined in Ruby. When would you want to use it?

sawa
  • 165,429
  • 45
  • 277
  • 381
  • Are you asking why the language allows you to write `+42` instead of simply `42` or why is there a method for it? Also *"the design philosophy of Ruby by Matz is that a feature would not be added just for symmetry"* - [Citation needed]. – ndnenkov Jan 12 '16 at 16:43
  • @ndn What is the difference between them? As for the citation, he repeats it everywhere on the issue tracker in response to some feature request. – sawa Jan 12 '16 at 16:44
  • One assumes that `+42` should be invalid syntax, the other that the implementation just shouldn't be available via the public API. – ndnenkov Jan 12 '16 at 16:45
  • @ndn As I wrote, I think it would be useful to allow the form `+42` to be syntactic, but its meaning being defined by some user (so that `+42` should raise an undefined method error out of the box). – sawa Jan 12 '16 at 16:47
  • I can't think of a single widely used language in which `+42` doesn't equal `42` and instead gives you an error. – ndnenkov Jan 12 '16 at 16:51
  • Btw just the other day I stumbled upon [this](https://redmine.ruby-lang.org/issues/3131), to suggest it's against the philosophy is strange. – ndnenkov Jan 12 '16 at 17:02

0 Answers0