7
123abc
3y

"not boolean" statement can be written as "(boolean+(-1))**2". Pls comment a better alternative lmao

Comments
  • 7
    Oh god why :D
  • 4
    Since you tagged python, isinstance(var, bool) ?

    PS. I hate and try not to use python, but if I recall correctly there's some oddities with bools and ints so not sure if it'd work
  • 1
    @12bitfloat im avoiding if else lol
  • 2
  • 1
    @ScriptCoded bool returns 0 or 1 if used arithmetically
  • 2
    I don't know about python but !!x is always a classic one

    Edit: `not not x` seems to do the trick
  • 1
    @12bitfloat thanks but im trying to avoid 'not' because i cant use it arithmetically
  • 8
    Just burn it to the ground. All of it.
  • 4
    @123abc Hm okay, no logical operators

    How about just `1-bool`. It doesn't evaluate to a boolean but I don't think your original expression does either
  • 2
    @12bitfloat why didnt i think of that lmao. Thanks!!!!
  • 2
    1-boolean
  • 4
    Branchless always fascinated me. I don't do it in python because I like to use python as more of a clean to read but less efficient tool. But in C++ I love these
  • 3
    While this might be a good brain exercise, aren't a lot of compilers doing the optimisation step for you anyway?
  • 2
    @kamen i guess it's more about code aesthetics, ya know, having less lines of code... wait no, that's horrible code aesthetics. A lame excuse to have a seemingly better Maintainability Index for saving 2 lines of code
  • 1
    Would then '1 - boolean' work?
  • 0
  • 0
    Nobody codes Java these days...
Add Comment