Kotlin Coroutine Confidence: Add formatter off/on comments (pg 162)

As a minor suggestion, in timers/v19/src/main/kotlin/com/example/timers/TimerApplication.kt, you might want to consider adding // @formatter:off and (optionally) // @formatter:on comments:

val timer = java.util.Timer()

// @formatter:off
fun main() {                               /* Secret hidden brackets */
  println("3…")
  timer.schedule(1000)                         {
  println("2…")
  timer.schedule(1000)                         {
  println("1…")
  timer.schedule(1000)                         {
  println("Liftoff!")
  timer.cancel()                               } } }
}
// @formatter:on

While this appears fine in the book, and should appear as desired in the code in someone’s IDE, there is the possibility that someone might reformat the source code at some point, such as when first starting out. (I have been known to do that sometimes.) In such a case, the non-standard formatting being used in this example would be lost. You could even just put the // @formatter:off comment before the import statement so it is out of the way, and wouldn’t show in the book’s snippet.

Of course this assumes the user has the “Turn formatter on/off with markers in code comments” option enabled. (IntelliJ IDEA documentation). And to be honest, I can’t remember what the default is. You could potentially add a .editorconfig file to the root of the downloaded source with this enabled:

ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true

The EditorConfig plugin is a bundled plugin, and so this file will take effect.

If you do add the .editorconfig file, you may also want to include the indenting settings since the 2-space indent being used may conflict with a user’s more typical 4-space default:

[*]
indent_size = 2
indent_style = space
tab_width = 2
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true