Integer literals in @rustlang can't be passed to functions that take floating point types. I've known this for a while, but are the reasons why written somewhere? Why was it necessary to make people write f(2.0) instead of just f(2)? Is there a reason against allowing this?
-
-
Automatically casting hides the (small) performance cost of the conversion and allowing a float to be written without the .0 hides the fact that is is a float.
1 reply 0 retweets 0 likes -
Sorry, I must not be being clear. I'm not suggesting *any* automatic or implicit casting. I totally agree that doing that is BAD. I'm only talking about literals. It should be valid to write f(2) and f(2.0). Integer literals, in this one specific case, should be valid.
1 reply 0 retweets 0 likes -
But the first option there implies that f can take an int. Without looking at the sig there's no way to know it's actually a float. Not a big deal (arguably) for small codebases written by one person, but a large codebase with many devs could have issues
1 reply 0 retweets 0 likes -
I don't know about how big of an issue it would actually be. First of all, I think it is common to know about the type signature of the function you're calling. Second, I don't think adding this extra thing you have to remember adds much value. Is 2 really different from 2.0?
1 reply 0 retweets 0 likes -
If you're writing it sure, but what if you're reading or modifying someone else's code?
1 reply 0 retweets 1 like
Both of you have laid out the arguments from both sides. We picked the conservative path for now. We can always add this, but once added, can never remove
-
-
Agreed! Thanks for the discussion!
0 replies 0 retweets 0 likesThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.