https://kotlinlang.org logo
#codereview
Title
# codereview
j

Jasmin Fajkic

02/02/2023, 1:55 PM
Hello. I have function in viewmodel that update index and based on current question send answer to the server. I would like some help how to make this code a little bit cleaner- Here is full gist viewmodel. https://gist.github.com/Jalson1982/83f482230ef1c68ae7a775f5459aef3c
👍 1
👎 1
c

Colton Idle

02/03/2023, 5:29 AM
theres a lot going on there so its hard to focus on something specific but overall i think it looks good.
p

Paul Woitaschek

02/04/2023, 4:46 PM
In the gist you can give it the
.kt
extension. Then we’ll have proper syntax highlighting. There is way too much stuff going on to give a proper code review in a short amount of time so I have fed it to chatGPT: 1. Use
null
checks and default values for the saved state handle instead of using the Elvis operator in the
survey
property. 2. Use a separate function for the
parsedSurvey
object to avoid repeating the same code. 3. Simplify the repeated code in question answer functions by creating a separate function that takes the question id and answer data as parameters. 4. Extract the state update code into a separate function to avoid duplicating code and make the code more readable. 5. Consider renaming functions to follow the Kotlin naming conventions and to better describe the actions being performed. It then gives an example that restructures your code but these 5 points should give you already a proper head start
7 Views