question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update import code style in samples

See original GitHub issue

In 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
soywizcommented, Mar 27, 2018

I have added a note in the documentation about this: https://ktor.io/features/locations.html#route-handlers

1reaction
rhartercommented, Mar 26, 2018

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.

screen shot 2018-03-26 at 10 01 07 am

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…”).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code style schemes | IntelliJ IDEA Documentation - JetBrains
Press Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. ; Click the Show Scheme Actions button and select Import...
Read more >
Python import: Advanced Techniques and Tips
The Python import system is as powerful as it is useful. In this in-depth tutorial, you'll learn how to harness this power to...
Read more >
Code style options and code cleanup - Visual Studio (Windows)
Learn how to configure Visual Studio to apply code style preferences using the Code Cleanup (Visual Studio 2019) and Format Document (Visual ...
Read more >
PEP 8 – Style Guide for Python Code
Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants....
Read more >
Editing Python in Visual Studio Code
For example, you may see import matplotlib as a suggestion, but not import ... The Python extension supports source code formatting using either...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found