```fun onValueChange(phone: String) { viewMode...
# android
y
Copy code
fun onValueChange(phone: String) {
    viewModelScope.launch {
        if (phone.length >= 10) return@launch
        if (!phone.onlyNumberCheck()) return@launch
        if (uiState.value.screenState == ScreenState.Loading) return@launch

        _phone.emit(phone)
    }
}
vs
Copy code
fun onValueChange(phone: String) {
        viewModelScope.launch {
            if (
                phone.length >= 10 ||
                !phone.onlyNumberCheck() ||
                uiState.value.screenState == ScreenState.Loading
            ) {
                return@launch
            }

            _phone.emit(phone)
        }
    }
Which is the most suitable style in this case? one if or 3 line if
a
I prefer (1); more readable. They could also be moved out, though.
e
considered
when
?
y
Maybe But now we are dusscussing which one if reccomended way?
p
I personally dislike placing validation logic or any business logic directly in control flow structures like
if/else
or the more general
when
. I like creating a separate function so it looks 1 line per condition. In above option I would pick
1
s
y
thanks everyone for saying their opinions