4 ms·
Indeed, you would need to check that the mask ends up being exactly alpha and blue, otherwise it's just an automatic boolean conversion from integer to boolean,
by fwsgonzo 4y ago
Indeed, you would need to check that the mask ends up being exactly alpha and blue, otherwise it's just an automatic boolean conversion from integer to boolean, which many languages are doing away with due to all the bugs it produces.
- svnpenn 4y agoYeah, you cant do that in Go, even explicitly: // cannot convert i (variable of type int) to type bool bool(i) youd need to use a function: func to_bool(i int) bool { return i != 0 }
- samatman 4y agoSeems a bit mean-spirited to provide casts but not that one.
- svnpenn 4y agonot really. Go has no concept of truthy: https://developer.mozilla.org/docs/Glossary/Truthy https://developer.mozilla.org/docs/Glossary/Truthy and I fully support that decision. If you want to use a boolean, you need to be explicit about it.
- samatman 4y agoA statically typed language shouldn't indulge in truthiness, no. But a cast is isn't truthiness, it's truth: the meaning of "make this int impenetrable to all but truth and falsehood" is in practice well defined, there's nothing implicit happening here. The compiler isn't going to make that function, it's going to optimize back to a cast to boolean. Why make the poor shmoe user type it out?
- svnpenn 4y agoCast int8 to int16 isn't the same thing as int to boolean. In the first case, you get the same number (ignoring wrapping issues). In the second case, you're asking the compiler to make an arbitrary decision about what numbers go to what booleans.
- samatman 4y agoThere is nothing arbitrary whatsoever about the conversion of any string of bits to a boolean, it is false iff none of the bits are 1. If you want to call it arbitrary, it's been arbitrated decades ago, but Boolean logic is much older than computers and works as it does for a reason. I suspect you know that.
- svnpenn 4y agothe number 9, is not the same thing as "true". some people may want it to be, it might be convenient for some people if a compiler treats them as the same thing, but they aren't. In my opinion, its an anti-pattern to have the compiler make these type of decisions. Instead of writing and reading code that is explicit, you're writing an abbreviated version of what you want, and assuming that the compiler will know what you mean.
- samatman 4y agoIt's Go pretending it's a kind of language it isn't, and making the user do the teapot dance instead of cooperating. People keep telling me this koolaid is delicious but I just don't see it.