is there a convention for a placeholder to denote a section of code that won't be reached? for example, after a loop with a return in it that always returns. i've been using
TODO()
and a short explanation of why it's unreachable, but is there a "better" way of doing it?
r
rajesh
07/11/2021, 6:33 AM
Comments are your best friends to describe code
s
SirNapkin1334
07/11/2021, 6:36 AM
i mean, that the section is unreachable, but the compiler can't know that, so is there any convention for what to do, asides from throwing an error that you know will never happen so the compiler knows the function can return?
f
Fleshgrinder
07/11/2021, 6:46 AM
I asked once for an
unreachable
like we have it in Rust and the consensus with the Kotlin devs was that
error("unreachable: description")
is good enough. Unlike Rust Kotlin doesn't need it to compile and adding it was perceived as adding unnecessary complexity.