News for hackers. Stuff that matters.
Re:Rust in 2016 by arielby on Friday August 14, 2015 @05:54PM (#10063200)
The annoying thing is that (because of type inference) parts of the expression could be within different expressions:

    fn required_bytes(width: u16, height: u16) -> u64 {
        let size = width * height; // what's the type of size?
        size + 12
    }
Re:Rust in 2016 by fpgaminer on Friday August 14, 2015 @07:54PM (#10063692)
True, type inference would make an ideal solution difficult. But I'm totally fine with the compiler failing to apply implicit casting when type inference is involved. This code is just as readable, if not better:

    fn required_bytes(width: u16, height: u16) -> u64 {
        let size: u64 = width * height;
        size + 12
    }
I just really don't want to have to write this all the time:

    fn required_bytes(width: u16, height: u16) -> u64 {
        let size = (width as u64) * (height as u64);
        size + 12
    }
Re:Rust in 2016 by dgoldstein0 on Saturday August 15, 2015 @10:43PM (#10067758)
I can sympathesize, but the last think I would want in a language is for benign looking refactorings to changes meaning. E.g.

    let a: u16;
    let b: u16;
    fn f(x: u32) -> ...

    f(a*b) // 32 bit result
    
    let x = a*b; // x is u16
    f(x)
Now there is a sane answer to this: define multiplication to always result in larger integer types, and require some explicit downcasting. But I'm not sure anyone will go for this.
Re:Rust in 2016 by echaozh on Friday August 14, 2015 @09:06PM (#10063895)
If there is a type inferred, single character operator which can cast one numeric type to another, both sides can be happy.
Re:Rust in 2016 by xyproto on Saturday August 15, 2015 @03:10AM (#10064608)
This way of thinking leads to ASCII spaghetti as features are added over time.
Re:Rust in 2016 by coldtea on Saturday August 15, 2015 @10:49AM (#10065508)
Should be u16 at first (or u32 for overflow?) and promoted to u64 when returning from the function.