this post was submitted on 28 Oct 2024
514 points (100.0% liked)

Programming Humor

3071 readers
1 users here now

Related Communities [email protected] [email protected] [email protected] [email protected]

Other Programming Communities [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 21 points 6 months ago* (last edited 6 months ago) (7 children)

Those are rookie lines of code numbers right there.
I would have done it without the ==

internal static bool AreBooleansEqual(bool orig, bool val)
{
    if(orig) 
    {
        if(val)
            return false
        return true
    }
    if(val)
        return true 
    return false
}

Don't know why their code returns false when they are equal but I'm not going to dig through old code to refactor to use true instead of false.

[–] [email protected] 9 points 6 months ago (1 children)

you can also use XOR operation

return (X || Y) && !(X && Y)
[–] [email protected] 2 points 6 months ago* (last edited 6 months ago)

I was debating on bitwise operations, but decided on super basic if statements which I think the compiler would optimize, happy to see the logical operation form too

load more comments (5 replies)