
Javaru
Kotlin Coroutine Confidence: Change function name, maybe (pg 182)
For pets/v2/src/main/kotlin/com/example/pets/Helpers.kt
(and in subsequent versions), I think it might be helpful to change the block
parameter name to something else.
suspend fun createWindow(
title: String,
block: suspend CoroutineScope.(JFrame) -> Unit
): Unit = withContext(Dispatchers.Main) {
Understandably in Kotlin block
is a common name for a function type parameter that is block of code to be executed (such as in the case of the Kotlin scope functions). But here I think the name can cause confusion due to the ambiguity with blocking code in the context of discussing Coroutines. Especially given it’s signature is block: suspend...
. In my case I saw its use before I saw its definition and started to think there was a new Coroutine block()
function we were about to learn about. Perhaps codeBlock
might be a better name , or create
? (create
makes more sense at the point its called in my humble opinion.)
Also, unless I am mistaken, this is the first time we have seen the suspend
key word as part of a function type parameter definition. So a couple of sentences highlighting that fact might be helpful. Like “hey did you notice we can define function type parameters as suspending functions?”
book-kotlin-coroutine-confidence version B3
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /centos
- /ash
- /php
- /deepseek
- /zig
- /scala
- /html
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /textmate
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /julia
- /slackware
- /c
- /neovim