News for hackers. Stuff that matters.
Re:SQL Anti-Patterns You Should Avoid by BuyMyBitcoins on Saturday October 18, 2025 @12:48PM (#45628654)
I am surprised at common it is for software engineers to not treat booleans properly. I can’t tell you how many times if seen ‘if(IsFoo(X) != false)’

It never used to bug me as a junior dev, but once a peer pointed this out it became impossible for me to ignore.

Re:SQL Anti-Patterns You Should Avoid by furyofantares on Saturday October 18, 2025 @03:31PM (#45629809)
The most egregious one I saw, I was tracking down a bug and found code like this:

    bool x;

    ...

    if (x == true) {
        DoThing1();
    } else if (x == false) {
        DoThing2();
    }
And of course neither branch was hit, because this is C, and the uninitialized x was neither 0 nor 1, but some other random value.
Re:SQL Anti-Patterns You Should Avoid by tomjakubowski on Saturday October 18, 2025 @04:42PM (#45630208)
Sometimes this kind of thing happens after a few revisions of code, where in earlier versions the structure of the code made more sense: maybe several conditions which were tested and then, due to changing requirements, they coalesced into something which now reads as nonsense.

When making a code change which touches a lot of places, it's not always obvious to "zoom out" and read the surrounding context to see if the structure of the code can be updated. The developer may be chewing through a grep list of a few dozen locations that need to be changed.

Re:SQL Anti-Patterns You Should Avoid by Rexxar on Sunday October 19, 2025 @05:34AM (#45633049)
Maybe it was initially supposed to be a sort of "3-value boolean" (true/false/undefined) and not a standard bool. You can (rarely) meet this pattern in c++ if you use boost::tribool or in c# if you have a nullable bool. There is probably similar thing in other languages.
Re:SQL Anti-Patterns You Should Avoid by furyofantares on Sunday October 19, 2025 @01:57PM (#45636319)
It was definitely just bad code.
Re:SQL Anti-Patterns You Should Avoid by munchlax on Saturday October 18, 2025 @02:45PM (#45629512)
People do that? This hurts my brain. if(IsFoo(X)) is clear and readable.
Re:SQL Anti-Patterns You Should Avoid by catlifeonmars on Saturday October 18, 2025 @02:19PM (#45629346)
Clearly the correct spelling is

`if(X&IsFooMask != 0)`

:)

Re:SQL Anti-Patterns You Should Avoid by 1718627440 on Sunday October 19, 2025 @04:55PM (#45637894)
I think of comparisons as a type conversion to a boolean. You wouldn't convert a boolean, but I like it to convert other types like an integer, even when the language rules would already specify the same I'm writing.