News for hackers. Stuff that matters.
Re:My Thoughts on Kotlin: Perspectives after 4 years by ab5tract on Saturday January 11, 2025 @06:24AM (#42665134)
In Raku the ternary was changed to ‘exp ?? True !! False’ to free up the single characters ‘?’ and ‘:’ for other purposes.

IME it’s not such a large shift for the developer (still easily recognizable as a ternary) while also having the benefit of slightly increasing the visibility of ternary expressions in the coding experience.

Edit: Thanks for the coroutine reading recommendation. I’ve been struggling a bit with them and have a few in use but would definitely like to grok them better.

Re:My Thoughts on Kotlin: Perspectives after 4 years by simon_void on Saturday January 11, 2025 @04:04PM (#42668911)
I'm actually in team no-ternary operator in Kotlin, simply because there shouldn't be two ways of doing the same thing. Maybe the problem is a linter issue: for me the main point of the ternary operator to have a very concise expression, a one-liner. But maybe our linters warn when a) we use if-else without braces and b) we put everything on the same line!?? Btw there is already another way to write the ternary operator in Kotlin (assuming the positive-case value of expression X is non-nullable): "C ? X : Y" -> "X.takeIf { C } ?: Y" https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/take-if... Though I admit, I've never used this version either.