Update import code style in samples
See original GitHub issueIn the samples it would be very nice to have explicit imports, as opposed to the standard start imports. While I understand start imports is part of the official Kotlin code style, the samples are meant to serve as a learning documentation, and start imports don’t suite that well.
For instance, I was just looking at the Kweet sample in Github and it’s very difficult to understand that I should be importing io.ktor.locations.post
instead of io.ktor.routing.post
. While I can see that the io.ktor.routing.*
package is not imported, without knowing first where to look that becomes cumbersome.
I also understand that I could download the sample and run it in IntelliJ to get that info, but that is a commitment I rarely make with sample code, since it’s usefulness is usually short lived.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:9 (4 by maintainers)
Top GitHub Comments
I have added a note in the documentation about this: https://ktor.io/features/locations.html#route-handlers
I understand the problem of having to change code styles just for samples, and how that could be cumbersome. I’m not sure of a good solution for that.
As for autocompleting, In the case of a conflict users are presented with the options in a list that shows the full package of the import (for extension functions, at least), so that is the point that I think this could clarify.
In this example, IntelliJ’s auto complete actually defaults to the wrong choice, so simply typing alt-return results in broken code.
Understanding the burden of multiple code styles (not sure IntelliJ support per-module code styles 😉), perhaps a documented approach would be better. Short of clarifying in the API (identical signatures on extension functions seems extremely error prone), I think it would help to either comment inline where there are multiple choices (deleting all imports and seeing what IntelliJ can’t choose for you is a decent way to identify these) or mentioning in the readme what APIs will be used (“This sample uses the
io.ktor.locations
package…”).