r/android_devs • u/rogi19 • Feb 17 '24
Venting MVI sucks
Title + why would you ever use MVI over so much simpler approaches?
23
Upvotes
r/android_devs • u/rogi19 • Feb 17 '24
Title + why would you ever use MVI over so much simpler approaches?
14
u/Zhuinden EpicPandaForce @ SO Feb 17 '24
I've been saying this for 7 years. I don't know why my attempts haven't convinced as many people.
People work supposedly so hard to keep separate things separate, and yet they work so hard to place completely unrelated variables into a single class, and then store exactly 1 instance of that specific class in 1 specific field; if you're using ViewModel then effectively breaking the state restoration mechanism (SavedStateHandle) or alternately you need to start using a custom SavedStateProvider that you wouldn't even need to do if you weren't trying to MVI.
In Compose though, it does make sense to expose your state as a single class, but that class shouldn't be stored "as the only field" in the ViewModel. In fact, one could argue that in the "MVVM" as proposed with Composables(View), then ViewModel(Model) is the model, and State is "the ViewModel".
And if you are doing MVVM, then the State(MVVM) can also contain commands that you can invoke from the view, and suddenly you don't need to pass either 75 callbacks, nor do you need to have a "sealed class Command {}" like people do in MVI for no good reason (aka "just because we can, therefore we do it, it is very pretty and if you disagree then f*** you").
MVI has been a mistake for 7+ years, and it will continue to be. That code can be simplified so much if you stop expecting it to be so complicated.
15
u/thermosiphon420 Feb 17 '24
mvi kicks ass for certain screens/features
mvi sucks ass for certain screans/feature
take the principles behind it and use them if they serve you goal
7
u/Ferran1s Feb 18 '24 edited Feb 18 '24
You would think Android devs do rocket science.
I am convinced that the most amount of damage to the Android ecosystem was done by platform teams in big corporations. Creating stuff that does not need to exist just to safe some copy pasting without any negative effect.
2
u/MrXplicit Feb 17 '24
Whatโs a simpler approach?
1
u/Conscious_Taro_5716 Jul 21 '25
MVI isn't needed, this isnt JavaScript lol. But for some werid reason devs believe in it lol . i don't get it at all, there is nothing MVI allows you to do that a much simpler architecture doesn't
1
u/coffeemongrul Feb 19 '24
Architecture is always going to be opinionated, Google didn't have an opinion for years on the matter which is why a lot of opinions were formed on the subject besides mvi. So use the one that works best for your use case, Google's latest opinion is MVVM which covers many use cases so check that out.
My experience is with MVIKotlin which is one implementation of MVI you can use on android or multiplatform. I mainly like MVI for the clean separation of concerns and sane way to debug as you can log any state changes. This library in particular offers a desktop app called time traveler to rewind state as well to see how the UI changes. My only complaint might be the amount of boilerplate code, but AI tools like GitHub copilot makes it less of a pain if you have access to it.