<@U019AG342E5> Yes, ChatGPT is fascinatingly good at Kotlin :grin: I took it for a nice conversation...
d
@Youssef Shoaib [MOD] Yes, ChatGPT is fascinatingly good at Kotlin 😁 I took it for a nice conversational test-drive asking it to model "the behaviour of a lift in a building". We got to the point where it wrote in RGB Lighting for the lift, which cross-faded to a different autumn colour for each floor. Initially the timing of the cross-fade was Thread based, but I asked it - in English - to change that to a Coroutines approach and it just did it. Also asked for a
var
to be replaced with a
Flow
... all handled with only one mistake. When I pointed out the mistake, ChatGPT admitted to the bug and corrected it! I feel like this is the AI inflection point we've been hearing about... no it won't create you a complete software product, but it's already a highly valuable tool for bouncing ideas off and accelerating code production.
πŸ‘€ 2
blob open mouth 1
y
Yeah and honestly it offers a great starting point. It's like IntelliJ templates but even better. I can ask it to write me a script for practically anything, list off my requirements, and eventually, through some discussion, I have something I can easily edit into working code. It's absolutely far from perfect, but it feels like a great way to do refactorings that can be described in English and not necessarily thru a find and replace or an intellij action
I personally wonder if statically-typed, inferred languages like Kotlin might be the perfect fit for using such a language model as a companion, because they're able to detect a lot of errors that a language model might make (e.g. syntax, type mismatches, etc) at compile-time, while in something like python it'll blow up at runtime instead
I made it add type hints to the code, which is interesting because some of the methods it uses don't actually exist even in the library versions it claims to use (ktor 1.4.2 and kotlinx.html 0.7.2). It also didn't add a type hint to the
request
variable only, which I'm assuming is because the variable has its type determined directly by the type parameter.
e
Yes, here is an updated version of the Android activity that uses Jetpack Compose to show the text "Hello, World!" on the screen, wrapped in a
Scaffold
with a
TopAppBar
that says "ChatGPT App", and uses a custom blue color palette for the Material Design theme
Copy code
import androidx.compose.Composable
import androidx.ui.core.Text
import androidx.ui.core.setContent
import androidx.ui.graphics.Color
import androidx.ui.material.MaterialTheme
import androidx.ui.material.Scaffold
import androidx.ui.material.Surface
import androidx.ui.material.TopAppBar
import androidx.ui.tooling.preview.Preview

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            BlueTheme {
                MainScreen()
            }
        }
    }
}

@Composable
fun BlueTheme(children: @Composable() () -> Unit) {
    val blue = Color(0xFF0066FF)
    MaterialTheme(colors = bluePalette(blue)) {
        children()
    }
}

fun bluePalette(blue: Color) = lightColors(
    primary = blue,
    primaryVariant = blue.copy(alpha = 0.7f),
    secondary = blue,
    secondaryVariant = blue.copy(alpha = 0.7f),
    error = Color.Red
)

@Composable
fun MainScreen() {
    Scaffold(topAppBar = {
        TopAppBar(
            title = { Text(text = "ChatGPT App") }
        )
    }) {
        Surface(color = Color.Yellow) {
            Text(text = "Hello, World!")
        }
    }
}

@Preview
@Composable
fun DefaultPreview() {
    BlueTheme {
        MainScreen()
    }
}
Anything more complicated then that kind of broke it, but pretty cool 😎
For example I asked it to add MVI and UDF to update the text and it couldn't finish the code despite several prompts (in hindsight I could probably ask it to write the functions separately because there's a response word limit):
Copy code
import androidx.compose.Composable
import androidx.ui.core.Text
import androidx.ui.core.setContent
import androidx.ui.graphics.Color
import androidx.ui.material.MaterialTheme
import androidx.ui.material.Scaffold
import androidx.ui.material.Surface
import androidx.ui.material.TopAppBar
import androidx.ui.tooling.preview.Preview

sealed class MainState {
    data class Initial(val text: String) : MainState()
    data class Updated(val text: String) : MainState()
}

sealed class MainIntent {
    data class UpdateText(val text: String) : MainIntent()
}

fun mainReducer(state: MainState, intent: MainIntent) = when (state) {
    is MainState.Initial -> when (intent) {
        is MainIntent.UpdateText -> MainState.Updated(text = intent.text)
    }
    is MainState.Updated -> when (intent) {
        is MainIntent.UpdateText -> MainState.Updated(text = intent.text)
    }
}

@Composable
fun MainScreen(state: MainState, updateText: (String) -> Unit) {
    Scaffold(topAppBar = {
        TopAppBar(
            title = { Text(text = "ChatGPT App") }
        )
    }) {
        Surface(color = Color.Yellow) {
            Text(text = state.text)
        }
    }
}

class MainActivity : AppCompatActivity() {
    private val initialState = MainState.Initial(text = "Hello, World!")
    private val reducer = ::mainReducer

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            BlueTheme {
                MainScreen(state = initialState) { text ->
                    val intent = MainIntent.UpdateText(text = text)
                    val newState = reducer(state = initialState, intent = intent)
                    // Update the state with the new state
                }
            }
        }
    }
}

@Composable
fun BlueTheme(children: @Composable() () -> Unit) {
    val blue = Color(0xFF0066FF)
    val complementary = Color(0
o
It’s also pretty good in adding kdoc if you feed it with complete function
🫠 1