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.

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.

Paul Woitaschek

02/04/2023, 4:46 PM
In the gist you can give it the
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
checks and default values for the saved state handle instead of using the Elvis operator in the
property. 2. Use a separate function for the
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