It just plain makes more sense to have every other value, including negative ones be true besides 0. 0 is the only number where every bit is set to 0, every other value has at least one bit set to 1. This is even reflected in Assembly where you have the jnz (jump if not zero) and the jz (jump if zero) instruction.
That doesn't fucking matter if i want to dump the bits of cEmployee into an array of doubles, i'll better be able to do so. That should be explicit but definitely allowed!
You can easily just use an equality operator, as I already pointed out, such as this:
cEmployee.SomeProperty == 1 // 1 for true
Your bad implementation doesn't mean the language is poorly designed because it doesn't suit your needs. Booleans are not numbers. Same way strings aren't numbers and you can't cast them to ints.
Not exactly. The language looks like Java to me. At least in Java 8, 1 is not equivalent to true and 0 is not false. Even in the tutorials I see geeksforgeeks, they are using an if - else statement for the conversion. Edit: Just realised this is C#. Anyway, same issue here so. Implicit conversion from int to bool is not allowed.
It's C#, and apparently they are using the unity engine which stores bools as 0 or 1 integers, which is why this works. They are only converting that 0 or 1 to false or true, in theory it should never be a 2 or 3, if it is, something is messing up elsewhere.
Doesn't excuse the fact it's still badcode tho lol.
It's really annoying to see code like this (obviously not within the context of r/badcode when the author realises it's bad, but like actual production code). The System namespace has like a million general-purpose exception classes that can be applied to almost every scenario. Why aren't people using them?!?!
44
u/Knuffya Feb 02 '22
it is wrong though.
int(34) should be true. just as any integer > 0