News for hackers. Stuff that matters.
Re:Rust in 2016 by prewett on Friday August 14, 2015 @10:11PM (#10064053)
Here's why you might not want to have type conversion. I ran into this today:

class String {

  int find(char needle, int startIdx);
};

I ended up calling:

   int idx = find(startIdx, ';');
C++ happily converted my char to an int, and my int to a char, no warning or anything. Surprisingly, the code appeared to work for months, and then when I upgrade Xcode to the beta, it started failing. Weird.

I end up casting stuff when I do math, anyway, because I can never remember when 'int op float' and 'float op int' results in an int or a float, and every time I don't it ends up as a truncated int when I wanted a float in [0, 1]. So, a little more painful to have to cast stuff around, but at least you find out quickly about my find() bug and you don't end up with something like

   if (secondsFromMidnightInFloat / 86400 > .5) {...}
always fails. I can't tell you how much time I've wasted tracking something like that down, despite my diligence in adding (float). That and that stupid "->" for pointers drive me nuts. Even more than header files.
Re:Rust in 2016 by kbenson on Friday August 14, 2015 @10:52PM (#10064129)
From the discussion linked[1] in another reply at your level, I believe the proposed automatic type conversions are only for when there's no data loss, and there needs to be explicit conversions whenever loss of information is possible. That is, it's implicit for i32 -> u32, or i32 -> i64, but not for something like i32 -> i8 (such as the int to char conversion you mentioned), which would need to be explicitly converted.

1: https://internals.rust-lang.org/t/implicit-widening-polymorp...

Re:Rust in 2016 by rectang on Saturday August 15, 2015 @10:59AM (#10065540)
i32 -> u32 is not lossless, since u32 cannot represent negative numbers. And indeed that's not listed in the implicit conversion table in the page you linked to.
Re:Rust in 2016 by kbenson on Saturday August 15, 2015 @01:20PM (#10066021)
You're right, I want clearly thinking about that. Thanks.
Re:Rust in 2016 by blub on Saturday August 15, 2015 @07:41AM (#10065128)
The first case will be detected by -Wconversion, however you have to enable it.

For the second case, correct me if I'm wrong, but I think both float / int and int / float have a float result. In fact, pretty much all operations involving an int and a float will have a float result.