I don't like it, because \ is an escape character. I don't honestly think that it's a big deal overall. With a different character (but which), maybe. But \ has too much meaning already. I also think that this would be *too* dramatic a change, changing the very nature of working with Ruby. --Austin
Symbol characters are too rare to be used so lightly. I think you'd want much broader use before considering something like this. This also breaks code that assumes integer division yields an integer (sounds like this RCR wants it to be a float). Just put a .to_f on one of your operands and be done with it. Eric
Actually, I agree in part with the RCR. The fact that 3/2 is either 1 or three-halfs depending on whether mathn is loaded or not is not a good thing.
Also, I would argue that changing the behaviour of / depending upon whether its arguments are float or int is not good either. Integer and floating point divisions are rarely substitutable for each other in any algorithm. Therefore almost every use of the division operator with non-literals should apply to_i or to_f to its non-literal arguments to ensure the proper operation.
That being said, I don't like the choice of backslash for integer division, I think there are too many problems with that choice. Other choices are not much better. // is possible, but it looks like an empty regular expression. @/ is another possibilty (but its kinda ugly, don'tcha think?).
In the end, we already have .div for integer division. Mathn adds .rdiv for rational division. What would make me happy is something that unconditionally represents floating point division, perhaps a .fdiv ? Then leave / for everyone who doesn't care what kind of division they are performing.
Sorry for the rant. I'm going to remain neutral on this RCR for now. I agree something should be done, but I don't like the backslash operator.
-- Jim Weirich
(Responding to an earlier comment):
This also breaks code that assumes integer division yields an integer
Code that assumes integer division yields an integer is already broken in that it cannot be used in any program that might also require the mathn library.
That's part of the current problem. -- Jim
The behavior of / is the thing I like least about Ruby.
This is one of those things that has come up again and again. Olathe, you should go read the several discussions which have taken place on ruby-talk and try to strengthen the argument or I fear this RCR will be quickly rejected.
I'd prefer the syntax be different ('//' perhaps?), but I like it otherwise.
Symbol characters are too rare to be used so lightly. I think you'd want much broader use before considering something like this. This also breaks code that assumes integer division yields an integer (sounds like this RCR wants it to be a float). Just put a .to_f on one of your operands and be done with it. Eric
Actually, I agree in part with the RCR. The fact that 3/2 is either 1 or three-halfs depending on whether mathn is loaded or not is not a good thing.
Also, I would argue that changing the behaviour of / depending upon whether its arguments are float or int is not good either. Integer and floating point divisions are rarely substitutable for each other in any algorithm. Therefore almost every use of the division operator with non-literals should apply to_i or to_f to its non-literal arguments to ensure the proper operation.
That being said, I don't like the choice of backslash for integer division, I think there are too many problems with that choice. Other choices are not much better. // is possible, but it looks like an empty regular expression. @/ is another possibilty (but its kinda ugly, don'tcha think?).
In the end, we already have .div for integer division. Mathn adds .rdiv for rational division. What would make me happy is something that unconditionally represents floating point division, perhaps a .fdiv ? Then leave / for everyone who doesn't care what kind of division they are performing.
Sorry for the rant. I'm going to remain neutral on this RCR for now. I agree something should be done, but I don't like the backslash operator.
-- Jim Weirich
(Responding to an earlier comment):
Code that assumes integer division yields an integer is already broken in that it cannot be used in any program that might also require the mathn library.
That's part of the current problem. -- Jim
The behavior of / is the thing I like least about Ruby.
This is one of those things that has come up again and again. Olathe, you should go read the several discussions which have taken place on ruby-talk and try to strengthen the argument or I fear this RCR will be quickly rejected.
I'd prefer the syntax be different ('//' perhaps?), but I like it otherwise.