I see a “magic” code in <JetBrains/skiko> …:joy:
# random
I see a “magic” code in JetBrains/skiko😂
🤣 2
😄 1
🪄 3


There is no
in kotlin
Aside from the artistic looks, why would anyone do
if ("literal" == variable)
in Kotlin when you can do
if (variable == "literal")
even when the variable might be null? (By the way, the expressions 0, 1, etc, look more like Fortran label numbers to me rather than resulting values.)
It is probably a defensive habit from languages where assignment is an expression and types can be coerced to boolean implicitly.
if ("literal" = variable)
would be a compile error while
if (variable = "literal")
would be a runtime bug.
Thanks. Even when I was a C and C++ developer, I still didn't use Yoda conditions because both the IDE and the compiler gave clear warnings when using
instead of
I heard this once from an older developer, but I haven't heard it anywhere else, but "apparently" some early compilers optimized checking against a literal better if the literal was the first argument? It sounds more absurd now that I say it out loud, so idk if there's any truth to it
"Yoda conditions", huh TIL