Skip to content

RBE promulgates a fallacy about time #1995

@iainism

Description

@iainism

The example code given by New Type Idiom promotes the idea that a year is 365 days. This is well-established to be a fallacy, e.g. '3' here: https://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time

A better example that avoids the fallacy would use unit conversion within an alternative system of measurement, e.g. pounds to kg (and vice-versa):

struct Kilogrammes(i64);

struct Pounds(i64);

impl Pounds{
    pub fn to_kilogrammes(&self) -> Kilogrammes {
        Kilogrammes((self.0 as f32 / 2.20462262184878) as i64) // Modify precision as needed
    }
}

impl Kilogrammes {
    pub fn to_pounds(&self) -> Pounds {
        Pounds((self.0 as f32 * 2.20462262184878) as i64)
    }
}

fn is_safe(mass: &Kilogrammes) -> bool { // Uses generally accepted limit of 20kg for manual handling
    mass.0 <= 20
}

fn main() {
    let luggage_lb = Pounds(25);
    let luggage_kg = luggage_lb.to_kilogrammes();
    println!("Safe for manual handling? {}", is_safe(&luggage_kg));
    println!("Safe for manual handling? {}", is_safe(&luggage_lb.to_kilogrammes()));
    // println!("Safe for manual handling? {}", is_safe(&luggage_lb));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions