r/reactnative • u/[deleted] • Mar 21 '21
Flutter vs React Native: a principal engineer’s viewpoint (Part I)
I’m so fucking tired of this topic, of endless analysis paralysis and holywars people seem to be having, so here is my jerry can of fuel to the fire.
Disclaimer: I work as a principal engineer in a company that earns money from a mobile solution lineup. I have personally reviewed Flutter and React Native, and decided to go with the latter, but not because it is so wonderful.
Anyway.
Neither of frameworks is superior. In fact, both are garbage in one way or another. I mean, they are both brilliantly engineered, and their maintainers are really great specialists. They are garbage in the sense that neither will solve all your problems perfectly. In fact, every technology that exists out there is more or less unfit for the job you are struggling with. That’s what you get paid for: solving problems by using flawed tools to make imperfect solutions, that are simply better than no solutions at all.
Literally, stop hoping for The Perfect GUI Library, it will never exist. No kind grey bearded wizard will wave his wand and give you a magic tool that will allow you to make splendid apps in no time, and earn easy money by writing poetry in code. Anyone who tries to sell you this is preying on your naïveté. There will always be a catch.
Your job is not about that. Your job is not about making the Most Wonderful App Ever at all. Your users don’t really give a shit about what your app runs on, and even what performance you have managed to squeeze out of it. OCD clowns from Management can give you some hard time about it, but it’s likely because that particular manager has managed to disconnect themselves from the actual needs of the business and customers so much, that they have the time to holler about some minor bugs and performance hiccups you may have that are of no consequence to the users at all.
Your job as a person in Engineering is to help your business solve tasks it faces on the technological front, and to identify and take care of the most critical tasks first, and of other if you have some free time. You should worry about making things happen, not about finding the best application structure (I can’t call it “architecture”, sorry) or rewriting stuff from one framework to another.
If your business’s livelihood solely depends on your screen rendering 300 milliseconds faster, your business is up shits creek no matter what you do, because this is not a viable business scheme in the first place. If your business, on the contrary, is doing something impactful for the society, your app can be a webview running jQuery, and users will be happily using it daily.
Anyway. That was one long and boring intro. Sorry.
So, React Native and Flutter. A description is warranted of both, highlighting the most conceptually important things (and not marketing fluff that get repeated from one “highly reputable tech company’s 5-reasons-my-ass blog post” to another.
React Native: Escape Hatches and Capitalizing on prior art.
First there was React, a method of developing user interfaces that scaled amazingly well on the scale of Facebook and tons of other projects. It’s gravitas dragged in talent and created a huge and nice, if a little hectic, ecosystem around it. Lots of things sprang up from these approaches. For example, there is a wonderful library called Relay that is basically an advanced data layer that is already written for your app, provided you use GraphQL of course. React Native gets React updates almost for free. You get some of the smartest battle-tested GUI concepts like Suspense for free. You’ll soon get Concurrent Mode in all its glory. Building upon React was a design decision. It capitalized on prior art.
Naturally an idea to replace DOM entities with platform-native views came into people’s heads immediately, because native GUI frameworks are just as battle-tested as are browsers. Plus, all of the apps out there are native apps, and you can’t really adopt any technology that drags in a foreign non-native stack incrementally. Operating Native views was a design decision. It capitalized on prior art.
Leaving JS was a design decision too, because it allowed to run huge amounts of code that has already been written. Lots of libraries available in the JS ecosystem at that point were familiar with running in both browser and in the server environments. This was a design decision, that capitalized on… you get it.
React Native is all about capitalizing on prior art. It is also a very boring framework, you could literally write it yourself. When it is was unveiled, my colleague of that time, who wasn’t even a programmer, was in the process of finishing a prototyping tool with hot reloading that worked exactly like React Native would work. It is straightforward to understand, it has little magic in it, and as a senior engineer, I like it very much. I wrote patches (very rarely) for React Native because I understood how it worked.
React Native is actually full of escape hatches and customization points, sadly not all of them are documented though. It is very hackable, and projects like react-native-skia or react-native-v8 show that. Hermes shows that it can incorporate some of Flutter’s fortes like AOT compilation without breaking a sweat. JSI shows that you can call native APIs with the same performance as if you wrote it natively. And with all this you can still run Relay, soon in Concurrent Mode for Data Fetching, with Error Boundaries, Suspense and all other modern GUI engineering concepts.
That said, React Native is not an easy tool for beginners or people who seek to quickly switch from pure frontend (or pure native) development. It is utter garbage in terms of how it treats new developers. Its tooling has lots of moving parts and the official team seems not too interested in improving developer experience just one bit (it is mostly Callstack and Expo who push for that). It is not as thoroughly documented as it could be. It fails to formulate and describe its design decisions, even though they, IMO, are dirtily pragmatic and brilliant. It sometimes suffers from lack of curated libraries (again, no resources allocated on that, because an attempt was made and failed).
It should not position itself as a tool for novices, actually.
React Native is about transferring successful concepts between classic frontend engineering and native GUI engineering, not about hiding complexity. It is about scaling the concepts that your app is built upon, while aggressively incorporating and reusing everything that has been done before. It is a tool for the astute developer who questions what they are doing and why.
It is an immensely powerful idea of framework that is driven by concepts inspired by natural evolution driving forces, and while it may never become perfect, it will claw itself out of almost every problem there can be.
It can be staggeringly ugly, as some living and evolving organisms are, and it is absolutely imperfect, but it’s architecture (not to be confused with “application structure”) ultimately allows it to be improved one point at a time.
But this all are technical details. As I said in the intro, this is a ultimately only as important, as consequences for your business are. React Native will not allow you to make an app super quickly or super cheaply, but it can reduce your costs just enough to be useful, and, more importantly, it will allow you to incorporate prior art from both the JavaScript and Native ecosystems. Not only the actual code, but knowledge and concepts, which is arguably more important. You can teach JavaScript or TypeScript to any good native developer, who will bring their expertise to your team, and this knowledge will be relevant. You can bring JS frontend or full-stack people into the team by gradually introducing them into native shenanigans, and these people will bring their expertise and it will too be useful.
Ultimately, it helps immensely to have a team who can reason about the entire stack, because the worst thing you can have in a tech team in 2021 is partial blindness in some points of the tech stack and really narrow focus of some team members. It breaks team synergy, and it allows people to stop considering product in its entirety and lazily focus on their own small damp corner, all while slacking around and keeping people away from disturbing their comfort zone.
React Native is not perfect, but it enables some really powerful concepts in areas like competence management, which are beyond “writing code and making it run”.
Choosing React Native was a strategic decision for our team and we are still reaping the rewards. It was not all bright, and for some tasks we had, Flutter would have been way better. But I’ll first focus on positive sides of both and only then I’ll dive into the negative ones.
Part 2 will be about Flutter, their comparison with RN and numerous downsides of both, and Part 3 will be about my story with both and conclusions. All parts are (hopefully) coming soon…