Does anyone know if there is a way to verify code...
# announcements
n
Does anyone know if there is a way to verify code snippets in Kotlin docs? For example if I document a function and include an example of how to use it, to verify that it works as intended? Similar to rust or python? Example for python: https://docs.python.org/2/library/doctest.html
s
wow that’s extra af lol, but I guess that’s python for you
I’d probably guess that there isn’t a good Kotlin equivalent considering the REPL and the Kotlin JSR-223 stuff isn’t being developed on as rapidly
n
It’s good to verify your docs match what the current code implementation does.
s
you’re not wrong, but that doesn’t mean that having a mechanism that reads your docstrings to parse a syntax that mimics what the interactive interpreter output looks like to validate your snippets isn’t a bit excessive
I mean, it’s not so bad considering how docstrings work in python and how they’re literally properties of the objects you write them in, but still
that’s probably a bit of a hurdle for Kotlin, considering comments are just comments, though it wouldn’t be infeasible to add this kind of validation as a build step. It’d probably be out of scope for the Kotlin folks, though. Maybe as kotlin scripting gets better we’ll see a gradle plugin or something similar that provides this kind of validation
i
@nyxcharon You can use @sample tag and refer to a function with a compiled code sample: http://kotlinlang.org/docs/reference/kotlin-doc.html#block-tags
d