is there a convention for a placeholder to denote ...
# announcements
s
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
Comments are your best friends to describe code
s
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
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.
e
there are ways in which the Kotlin language could be evolved to make use of
unreachable()
, but they don't exist now (and the plan for exhaustive-when doesn't use it)
s
I just throw IllegalStateExcpetion.