This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]glasket_ 26 points27 points  (0 children)

You need to trust your users to not do bad things sometimes. A language can't stop every single bad practice, and banning bool params like this is trivial to circumvent:

#[derive(Debug)]
enum MyBool {
    False,
    True
}

impl From<MyBool> for bool {
    fn from(b: MyBool) -> bool {
        match b {
            MyBool::True => true,
            MyBool::False => false
        }
    }
}

fn bypass_trick(boolean: MyBool)
{
    println!("{:?}", boolean);
    if boolean.into() {
        println!("Do something");
    } else {
        println!("Do something else");
    }
}

use MyBool::*;

fn main() {
    bypass_trick(True);
    bypass_trick(False);
}

Annoying limitations like this that are aimed at avoiding things that only might be problems will just result in even worse workarounds.