• lad@programming.dev
    link
    fedilink
    English
    arrow-up
    3
    ·
    29 days ago

    This one:

    fn resize(width: u32, height: u32) {}
    fn offset(dx: u32, dy: u32) {}
    
    let f: fn(u32, u32) = if resizing { resize } else { offset };
    

    gets rewritten to something non-equivalent:

    struct Size {
        width: u32,
        height: u32,
    }
    
    fn resize(size: Size) {}
    
    // No more arguing about arguments
    let f: fn(Size) = resize;
    

    But I would say that the original idea of applying wildly different functions depending on a flag shouldn’t be easily achievable, because it’s a bad idea a lot of times.